[英]JavaScript popup to show only once
这是一个弹出淡入框的脚本,该框显示用户何时要离开网页。
我试图使其仅显示一次,所以当用户单击“ X标记”退出时,我不想再次显示它。 当前,无论单击多少次退出,它始终显示。
我们将不胜感激,因为我对javascript的了解非常有限。
JavaScript的
$(document).ready(function() {
$(document).mousemove(function(e) {
$('#exitpopup').css('left', (window.innerWidth/2 - $('#exitpopup').width()/2));
$('#exitpopup').css('top', (window.innerHeight/2 - $('#exitpopup').height()/2));
if(e.clientY <= 30)
{
// Show the exit popup
$('#exitpopup_bg').fadeIn();
$('#exitpopup').fadeIn();
}
});
$('#xmark').click(function(){
$('#exitpopup_bg').fadeOut();
$('#exitpopup').slideUp();
});
});
的CSS
#exitpopup {
text-align:center;
font-family:Arial, Helvetica, sans-serif;
}
#exitpopup h1 {
margin-top:0px;
padding-top:0px;
font-size:55px;
}
#exitpopup h2 {
margin-top:0px;
padding-top:0px;
font-size:35px;
text-transform:uppercase;
color: #ff5300;
font-weight:bold;
font-style:italic;
}
#exitpopup p {
text-align:left;
}
.button-popup {
background-color: #ff5300;
padding:40px;
color:#fff;
border:0px;
font-size:26px;
font-weight:bold;
}
.input-popup {
border: 5px solid white;
-webkit-box-shadow:
inset 0 0 8px rgba(0, 0, 0, 0.1),
0 0 16px rgba(0, 0, 0, 0.1);
-moz-box-shadow:
inset 0 0 8px rgba(0, 0, 0, 0.1),
0 0 16px rgba(0, 0, 0, 0.1);
box-shadow:
inset 0 0 8px rgba(0, 0, 0, 0.1),
0 0 16px rgba(0, 0, 0, 0.1);
padding: 15px;
background: #FFE2C6;
margin: 0 0 10px 0;
font-weight: bold;
font-size:16px;
}
#xmark {
position:absolute;
margin-left:-20px;
margin-top:-40px;
}
HTML
<div style="display: none; width:100%; height:100%; position:fixed; background:#000000; opacity: .9; filter:alpha(opacity=0.8); z-index:999998; margin-top:-15px;" id="exitpopup_bg"></div>
<div style=" margin-left: -20px; width:1000px; height:550px; display:none; position:fixed; color:#000; padding:40px 20px 20px 20px; z- index:999999; background:rgb(20, 20, 20); background: #f7f7f7; " id="exitpopup">
<div id="xmark"><img src="../slike/x-mark.png" /></div>
</div>
您可以只保留一个变量,作为是否打开了弹出窗口的标志。 页面刷新时,它将设置回false。
$(document).ready(function() {
var opened = false;
$(document).mousemove(function(e) {
$('#exitpopup').css('left', (window.innerWidth/2 - $('#exitpopup').width()/2));
$('#exitpopup').css('top', (window.innerHeight/2 - $('#exitpopup').height()/2));
if(e.clientY <= 30 && !opened)
{
opened = true;
// Show the exit popup
$('#exitpopup_bg').fadeIn();
$('#exitpopup').fadeIn();
}
});
$('#xmark').click(function(){
$('#exitpopup_bg').fadeOut();
$('#exitpopup').slideUp();
});
});
您可以只添加一个计数器变量。 像这样:
$(document).ready(function() {
var counter=0;
....
if(counter ==0) {
// Show the exit popup
$('#exitpopup_bg').fadeIn();
$('#exitpopup').fadeIn();
counter++;
}
}
});
在.slideup()
的回调中使用.remove()
.slideup()
:
$('#exitpopup').slideUp('fast', function(){
$(this).remove();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.