[英]Jquery popup display at once time on the same page
I have set my code like this, that when the page is refreshed it will show a popup and make the counter one.我已经这样设置我的代码,当页面刷新时,它会显示一个弹出窗口并使计数器成为一个。 And once the counter is one popup should not be displayed again.并且一旦计数器是一个弹出窗口就不应再次显示。
I am having this issue that it is showing and again on the same page and I want it to show the popup on the same page.我遇到了这个问题,它在同一页面上再次显示,我希望它在同一页面上显示弹出窗口。 When then is changed to another, then same process is to be repeated.当 then 更改为另一个时,将重复相同的过程。
var counter = 0;
counter ++;
if(counter == 1)
{
setInterval(function () {
$('.popup2, .overlay2').fadeIn();
}, 1500);
}
else {
$('.popup2, .overlay2').fadeout();
}
I have also tried this code but it is not working我也试过这段代码,但它不起作用
if ($ .cookie("popup_1_2") == null) {
setInterval(function () {
$('.popup2, .overlay2').fadeIn();
}, 1500);
$ .cookie("popup_1_2", "2");
}
You want to be using setTimeout for a single action after a time interval.您希望在一段时间间隔后将 setTimeout 用于单个操作。 SetInterval is for infinitely repeating events (until canceled) SetInterval 用于无限重复事件(直到取消)
I don't know why you need the counter though.我不知道你为什么需要柜台。 Instead just activate the popup on page load而是在页面加载时激活弹出窗口
$(document).ready(function() {
setTimeout(function () {
$('.popup2, .overlay2').fadeIn();
}, 1500);
})
if The counter was meant to somehow be aware if the same user had come back to the page a second time (and therefore don't show the popup, you could use localStorage, like如果计数器旨在以某种方式知道同一用户是否第二次返回页面(因此不显示弹出窗口,您可以使用 localStorage,例如
$(document).ready(function() {
let beentheredonethat = localStorage.getItem('popupviewed')
if (!beentheredonethat){
setTimeout(function () {
$('.popup2, .overlay2').fadeIn();
}, 1500);
localStorage.setItem('popupviewed','true');
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.