添加超时功能以显示带有cookie的模态

时间:2014-07-24 22:44:16

标签: javascript jquery cookies modal-dialog zurb-reveal

我已经成功使用此脚本设置了一个jquery cookie,它可以向网站访问者显示一个显示模式,但每天只显示一次。

<script type="text/javascript">
$(document).ready(function(){
        // if the cookie doesn't exist create it and show the modal
        if ( ! $.cookie('hereToday') ) {

        // create the cookie. Set it to expire in 1 day
        $.cookie('hereToday', true, { expires: 1 });

        //call the reveal modal
        $('#subscribe').reveal();
    }
});
</script>

如何在脚本中添加一个超时函数,在触发模态之前会增加几秒钟的延迟?

2 个答案:

答案 0 :(得分:1)

你必须使用setTimeout功能:

<script type="text/javascript">
$(document).ready(function(){
        // if the cookie doesn't exist create it and show the modal
        if ( ! $.cookie('hereToday') ) {

        // create the cookie. Set it to expire in 1 day
        $.cookie('hereToday', true, { expires: 1 });

        //call the reveal modal
        var delay=5000; //in ms, this would mean 5 seconds
        setTimeout(function(){
            $('#subscribe').reveal();
        },delay);
    }
});
</script>

答案 1 :(得分:0)

只需使用setTimeout。

setTimeout(function() {
    $('#subscribe').reveal();
},5000);

模态将在5秒后调用。

相关问题