gpt4 book ai didi

jquery - 按下 ESC 时关闭灯箱

转载 作者:行者123 更新时间:2023-12-01 01:55:14 25 4
gpt4 key购买 nike

我试图在按下转义键时关闭灯箱,但弹出窗口没有关闭。

$(document).keypress(function(e){

if(e.keyCode==27 && popupStatus==1){

disablePopup();
}
});

完整代码如下:

var popupStatus = 0;
var buttonDivID = "";
var conDivID = "";

//determine which div is clicked
function setDiv( div ) {
if( div==1){
conDivID = "#intro";
}
if( div==2) {
conDivID = "#presentation";
}
}

//loading popup with jQuery magic!

function loadPopup(){

//loads popup only if it is disabled

if(popupStatus==0){

$("#backgroundPopup").css({

"opacity": "0.7"

});

$("#backgroundPopup").fadeIn("slow");

$(conDivID).fadeIn("slow");

$(conDivID).CenterIt();

popupStatus = 1;

}

}

//disabling popup with jQuery magic!

function disablePopup(){

//disables popup only if it is enabled

if(popupStatus==1){

$("#backgroundPopup").fadeOut("slow");

$(conDivID).fadeOut("slow");

popupStatus = 0;
buttonDivID = "";
conDivID = "";
}
}



//centering popup

function centerPopup(){

//request data for centering

var windowWidth = document.documentElement.clientWidth;

var windowHeight = document.documentElement.clientHeight;

var popupHeight = $(conDivID).height();

var popupWidth = $(conDivID).width();

//centering

$(conDivID).css({

"position": "absolute",

"top": windowHeight/2-popupHeight/2,

"left": windowWidth/2-popupWidth/2

});

//only need force for IE6

$("#backgroundPopup").css({

"height": windowHeight

});
}

//CONTROLLING EVENTS IN jQuery

$(document).ready(function(){

$("#vid2").click(function(){
//set the lightbox divs
setDiv(2);
loadPopup();
});

//CLOSING POPUP

//Click the x event!

$(".popupContactClose").click(function(){

disablePopup();

});

//Press Escape event!

$(document).keypress(function(e){

if(e.keyCode==27 && popupStatus==1){

disablePopup();
}
});
});

另一种方法是单击 x 按钮,可以正确关闭弹出窗口。为什么这不关闭它?

最佳答案

这有效:

$(document).ready(function(){
$(document).bind('keydown', function(e) {
if (e.which == 27) {
alert('esc pressed');
}
});
});

关于jquery - 按下 ESC 时关闭灯箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3578630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com