Advertisement
AmourSpirit

lightbox with textarea example

Dec 22nd, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 3.36 KB | None | 0 0
  1.  <!DOCTYPE html>
  2. <html> 
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  6.     <!-- https://craig.is/killing/mice -->
  7.     <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mousetrap/1.4.6/mousetrap.min.js"></script>
  8. <title>Lightbox Test</title>
  9.     <style type="text/css">
  10.  
  11.         body
  12.         {
  13.             font-family: Helvetica, Arial;
  14.         }
  15.  
  16.         .backdrop
  17.         {
  18.             position:absolute;
  19.             top:0px;
  20.             left:0px;
  21.             width:100%;
  22.             height:100%;
  23.             background:#000;
  24.             opacity: .0;
  25.             filter:alpha(opacity=0);
  26.             z-index:50;
  27.             display:none;
  28.         }
  29.  
  30.  
  31.         .box
  32.         {
  33.             position:absolute;
  34.             top:20%;
  35.             left:30%;
  36.             width:500px;
  37.             height:300px;
  38.             background:#ffffff;
  39.             z-index:51;
  40.             padding:10px;
  41.             -webkit-border-radius: 5px;
  42.             -moz-border-radius: 5px;
  43.             border-radius: 5px;
  44.             -moz-box-shadow:0px 0px 5px #444444;
  45.             -webkit-box-shadow:0px 0px 5px #444444;
  46.             box-shadow:0px 0px 5px #444444;
  47.             display:none;
  48.         }
  49.  
  50.         .close
  51.         {
  52.             float:right;
  53.             margin-right:6px;
  54.             cursor:pointer;
  55.         }
  56.  
  57.         </style>
  58.  
  59. <script type="text/javascript">
  60.     jQuery(document).ready(function(){
  61.         jQuery('.lightbox').click(function() {
  62.             jQuery('textarea#lbcode').val(jQuery('.note').html());
  63.             jQuery('.backdrop, .box').animate({'opacity':'.50'}, 300, 'linear');
  64.             jQuery('.box').animate({'opacity':'1.00'}, 300, 'linear');
  65.             jQuery('.backdrop, .box').css('display', 'block'); 
  66.             Mousetrap.bind('enter', function() { jQuery('.lightbox-buttons .lightbox_save_close').trigger('click'); });
  67.             Mousetrap.bind('esc', function() { jQuery('.lightbox-buttons .lightbox_close').trigger('click'); });
  68.         });
  69.         jQuery('.lightbox_save_close').click(function(){
  70.             var strTxt = jQuery('textarea#lbcode').val().toString();
  71.             jQuery('.backdrop, .box').animate({'opacity':'0'}, 300, 'linear', function(){
  72.                 jQuery('.backdrop, .box').css('display', 'none');
  73.  
  74.             });
  75.             jQuery('.note').html(strTxt);
  76.             jQuery('textarea#lbcode').val(""); // clean up textarea
  77.             unbind_keys();
  78.         });
  79.  
  80.         jQuery('.lightbox_close').click(function(){
  81.             jQuery('.backdrop, .box').animate({'opacity':'0'}, 300, 'linear', function(){
  82.                 jQuery('.backdrop, .box').css('display', 'none');
  83.             });
  84.             jQuery('textarea#lbcode').val(""); // clean up textarea
  85.             unbind_keys();
  86.         });
  87.  
  88.         jQuery('.close').click(function(){
  89.             close_box();
  90.             unbind_keys();
  91.         });
  92.  
  93.         jQuery('.backdrop').click(function(){
  94.             close_box();
  95.             unbind_keys();
  96.         });
  97.     });
  98.  
  99.     function close_box()
  100.     {
  101.         jQuery('.backdrop, .box').animate({'opacity':'0'}, 300, 'linear', function(){
  102.             jQuery('.backdrop, .box').css('display', 'none');
  103.         });
  104.         jQuery('textarea#lbcode').val(""); // clean up textarea
  105.     }
  106.  
  107.     function unbind_keys()
  108.     {
  109.         Mousetrap.unbind('enter');
  110.         Mousetrap.unbind('esc');
  111.     }
  112. </script>
  113. </head>
  114. <body>
  115.     <h1>Lightbox Textarea Example</h1>
  116.     <a href="#" class="lightbox">Open Lightbox</a>
  117.     <div class="note"><p style="color:green;">Hello world</p></div>
  118.  
  119.     <div class="backdrop"></div>
  120.     <div class="box"><div class="close">x</div>This is the lightbox!!!<div>
  121.          <textarea id="lbcode" rows="8" cols="68"></textarea>
  122.         </div>
  123.         <div class="lightbox-buttons">
  124.             <a class="lightbox_save_close" href="#" >OK<a>&nbsp;<a class="lightbox_close" href="#" >Cancel</a>
  125.         </div>
  126.     </div>
  127.     </body>
  128. </body>
  129.  
  130. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement