Skip to content

Instantly share code, notes, and snippets.

@davidalexander
Created July 16, 2011 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidalexander/1086732 to your computer and use it in GitHub Desktop.
Save davidalexander/1086732 to your computer and use it in GitHub Desktop.
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