简体   繁体   English

苦苦挣扎jQuery延迟弹出窗体

[英]Struggling with jQuery delay popup form

I'm hoping for a little assistance with an issue I'm having. 我希望对我遇到的问题提供一些帮助。

I have a popup on my site newsletter-popup-conatiner . 我在我的网站newsletter-popup-conatiner上有一个弹出newsletter-popup-conatiner (yes, that is the actual misspell of container used throughout the site) (是的,这是整个网站使用的容器的实际拼写错误)

From what I understand, the following 'should' delay the popup by 5 seconds. 根据我的理解,以下'应该'将弹出窗口延迟5秒。

setTimeout(function(){
  $('#newsletter-popup-conatiner).show();
},5000);

Here is the newsletter module. 这是时事通讯模块。 After several unsuccessful attempts, I'm at a loss where to actually put the delay code. 经过几次不成功的尝试,我无法实际放置延迟代码。

$("#newsletter-popup-conatiner").mouseup(function(e){
        var popContainer = $("#newsletter-popup-conatiner");
        var newsLatterPop = $("#newsletter-pop-up"); 
        if(e.target.id != newsLatterPop.attr('id') && !newsLatterPop.has(e.target).length)
    {
      popContainer.fadeOut();
    }        
  });

  $('.hide-popup').on("click", function(){
    var popContainer = $("#newsletter-popup-conatiner");
    $('#newsletter-popup-conatiner')
    {
      popContainer.fadeOut();
    }
  });

  $('#dont_show').on("click", function(){
    $.cookie('popup_cookie', 'pclosed', {
      expires: 3,
      path: '/'
    });
    $('.hide-popup').trigger('click');
  });
  // console.log($.cookie('popup_cookie'));

  {% if settings.show_pupup and template == 'index'%}
  if($.cookie('popup_cookie') == 'pclosed') {
    $('.hide-popup').trigger('click');
  }
  {% endif %}

});

Any guidance would be greatly appreciated 任何指导将不胜感激

<body onload="myFunction()">

<script>
function myFunction() {
  setTimeout(function() {
    $('#newsletter-popup-conatiner').show(); 
  }, 5000);
}
</script>
</body>

You can try this. 你可以试试这个。 It will show your container after 5 seconds on loading the page. 它将在加载页面5秒后显示您的容器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM