I want a cross close button on top of my overlay.
I have an overlay which appears over my webpage. I want a cross symbol on top of my overlay so that users can closs the overlay. So How i can close the overlay if the user presses esca开发者_开发知识库pe key.
$(document).keyup(function(e) {
if (e.keyCode == 27) {
//close the overlay
}
jquery keyup
here is the fiddle http://jsfiddle.net/yJTJz/3/
This should do it..
$(document).keyup(function(e){
if (e.which == 27){
$('#closeButtonId').trigger('click');
}
});
assuming that your cross button has a click handler attached that closes the overlay..
$('#closeButtonId').click(function(){
$('#overlay').hide();
});
if (e.keyCode ==27){
$('#your x-button').click();
}
精彩评论