Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
jQuery Dismiss Lightbox with ESC
// Bind a custom event to the lightbox that can be triggered when it needs to be dismissed:
$('.lightbox').bind('dismiss', function() {
// code to dismiss lightbox
});
// Then just trigger that event when escape it pressed:
$(document).bind('keyup', function(e) {
if(e.keyCode == 27) {
$('.lightbox').trigger('dismiss');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment