Created
July 16, 2011 20:26
-
-
Save davidalexander/1086732 to your computer and use it in GitHub Desktop.
jQuery Dismiss Lightbox with ESC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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