jquery - 有没有办法让我的 cookie 弹出几秒钟的延迟?
问题描述
我正在寻找一种使用 Jquery 延迟弹出窗口的方法
你好,
我不擅长 Jquery,所以我一直在寻找一种方法来延迟我的弹出窗口几秒钟,然后再弹出。Jquery 现在正在使用 cookie 等等,这很棒。但我不知道如何在它弹出之前将其延迟 5 秒。
有人可以帮忙吗?
jQuery('.close').click(function(){
jQuery('#popup-container').fadeOut();
jQuery('#active-popup').fadeOut();
});
var visits = jQuery.cookie('visits') || 0;
visits++;
jQuery.cookie('visits', visits, { expires: 1, path: '/' });
console.debug(jQuery.cookie('visits'));
if ( jQuery.cookie('visits') > 1 ) {
jQuery('#active-popup').hide();
jQuery('#popup-container').hide();
} else {
var pageHeight = jQuery(document).height();
jQuery('#popup-container').show(0).delay(5000);
}
如果有人可以帮助我编写代码,那就太好了。
解决方案
将 CSS 更改为默认隐藏
#popup-container{
display: none;
width: 500px;
height: 600px;
position: fixed;
bottom: 0;
right: 0;
z-index: 999;
}
和 javascript
if (jQuery.cookie('visits') > 1) {
jQuery('#active-popup').hide();
// jQuery('#popup-container').hide();
}
else {
var pageHeight = jQuery(document).height();
setTimeout(function() {
jQuery('#popup-container').show();
}, 5000);
}
推荐阅读
- javascript - jQuery Steps - 重置到主要步骤
- tensorflow - 使用 CNN 和 LSTM 在 Tensorflow 中占位符大小和类型的错误
- angular - 仅当来自服务器端的数据时如何呈现 html
- android - Android:如何在自定义布局通知上捕获双击事件?
- excel - 索引匹配,向下拖动索引命令以从列中获取数据?
- php - 如何修改wordpress评论表单
- arrays - 使用 Mongodb 的 Node js 嵌套查询
- java - 如何为特定 url 启用 spring 安全性
- google-apps-script - 按名称和日期添加数据行
- vba - 我在访问中没有看到 VBA 代码的结果