【问题标题】:Is there a way to give my cookie pop up a delay of a few seconds?有没有办法让我的 cookie 弹出几秒钟的延迟?
【发布时间】:2018-12-24 15:18:40
【问题描述】:

我正在寻找一种使用 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);
      }

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

【问题讨论】:

    标签: jquery cookies popup delay


    【解决方案1】:

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

    【讨论】:

    • 它确实有效,但是当我转到另一个页面并返回主页时,弹出窗口又回来了。但它只需要在一个会话中显示一次。也许是某种冲突?
    • 我刚刚又看了一遍,但是它不起作用,cookie现在可以工作,但即使在替换代码后它仍然会立即显示
    • 你能创建演示页面吗?
    • 导航到其他页面并返回主页后,我看不到弹出窗口,除非我点击返回按钮时它会闪烁。尝试编辑的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-11
    • 1970-01-01
    • 1970-01-01
    • 2019-10-25
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    相关资源
    最近更新 更多