简体   繁体   English

5秒后显示div,然后每1分钟刷新一次div

[英]show div after 5 seconds and then refresh the div every 1 min

I have created a div into my page which i wanted to get load after 5 seconds the page get load. 我在我的页面中创建了一个div,我想在页面加载5秒后加载。 Then I wanted to refresh the div without refreshing the page after every 1 min. 然后,我想刷新div,而不要每1分钟刷新一次页面。 How can I achieve this functionality with the use of J query. 如何使用J查询来实现此功能。 My code look like this 我的代码看起来像这样

$(document).ready(
    function () {
        setInterval(function() {
            $('#newsletter').show();
        }, 100000);

  });

This upper block of code is only refreshing the div after 1 min. 上面的代码块仅在1分钟后刷新div。 But on page load , i want the div to be shown to the user after 5 seconds and then this block of code should executed. 但是在页面加载时,我希望在5秒后将div显示给用户,然后应该执行此代码块。

$(document).ready(function()
{
    setTimeout(function()
    {
        // Perform actions you need to
        setInterval(function()
        {
            // Perform them again every minute
        }, 60000);

    }, 5000);
});

I think what you were looking for is setTimeout 我认为您正在寻找的是setTimeout

Try it: 试试吧:

$(function(){
 setTimeout(function(){
$('#newsletter').show(); // to show div after 5 sec of page load

// To reshow on every one minute
setInterval(function() {
            $('#newsletter').show();
        }, 60000);
  }, 5000);

}); });

You've already got the base functionality there, so all you'll need to do is add a message to appear after 5 seconds. 您已经有了基本功能,因此您所要做的就是添加一条消息,在5秒钟后出现。 Something like this should work. 这样的事情应该起作用。

$(document).ready(function()
 {
   setTimeout(function() { 
          // show message
      },5000);

     setInterval(function() {
        $('#newsletter').show();
    }, 60000);
  });

Here is a jQuery solution: 这是一个jQuery解决方案:

$(document).ready(function () {
    var $newsletter = $('#newsletter')
        .delay(5000)
        .show(function() {
            setInterval(function() {
                // update the newsletter, e.g. set new text
                $newsletter.text(new Date());
            }, 60000);
        });
});

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

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