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(); } }); });
Comments
Post a Comment