首页 > 解决方案 > 有没有办法让我的 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);
      }

如果有人可以帮助我编写代码,那就太好了。

标签: jquerycookiespopupdelay

解决方案


将 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);
}

推荐阅读