首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在页面自动打开后设置jquery时间5秒

在页面自动打开后设置jquery时间5秒
EN

Stack Overflow用户
提问于 2015-08-06 18:00:26
回答 1查看 431关注 0票数 0

如何设置jquery在页面加载后5秒自动打开,5秒后关闭,我如何做呢?请帮帮我。

我的JS代码:

代码语言:javascript
复制
$(document).ready(function() {
    $('#my-welcome-message').firstVisitPopup({
      cookieName : 'homepage',
      showAgainSelector: '#show-message'
    });
 });
EN

回答 1

Stack Overflow用户

发布于 2015-08-06 18:48:34

你的问题有点不清楚。您想先检查一下cookie吗?如果cookie不存在,请在页面加载5秒后再显示消息吗?然后在5秒后关闭消息?

无论如何,您可以使用Javascript setTimeout在x毫秒后执行代码。

代码语言:javascript
复制
$(document).ready(function() {
    var timeOut;
    // use setTimeout to call the open function after 5 seconds
    timeOut = setTimeout(openMessage, 5000);

    function openMessage() {
        // your code to display message

        // the setTimeout again to run the close function in 5 seconds
        timeOut = setTimeout(closeMessage, 5000);
    };

    function closeMessage() {
        // your code to close the message
    }
});

这应该会给你指明正确的方向。如果你澄清你的帖子,我也许能帮上进一步的忙。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31862708

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档