jquery - How to add escape key functionality to close light box? -


i created lightbox using following script:

<script type="text/javascript">     $(document).ready(function(){             $(".btnaction").click(function(){                                                var objpopup = $($(this).attr("rel"));                  var mask = $("<div/>", {                     id : "mask",                     style: "background:#000; display:block;top:0;left:0;position:absolute;opacity:0.8;filter: alpha(opacity=80);width:100%;height:100%;z-index:9998;",                     click: function(){                         $(objpopup).hide();                         $(this).remove();                        }                        });                   $(".popupwrap").before(mask);                 objpopup.show();             });              $(".closeicon").click(function(){                 $(this).parent().hide();                 $("#mask").remove();             });      }); </script> 

how can implement esc key when clicked, lightbox close well?

thanks much.

you can add esc key listener document within $(document).ready() block, , repeat code have $('.closeicon').click() function, target lightbox it's id:

$(document).ready(function(){  // existing code      $(document).keyup(function(e) {          if (e.keycode == 27) { // esc keycode             $('#lightboxid').hide();             $('#mask').remove();         }     }); }); 

https://stackoverflow.com/a/3369624/1010337


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -