如何在事件上重置setInterval函数单击弹出关闭

时间:2017-07-24 14:19:35

标签: javascript jquery magnific-popup

            <script>
                $(document).ready(function () {
                    setInterval(function () {
                        $.magnificPopup.open({
                            items: {
                                src: '#test-popup'
                            },
                            type: 'inline'
                        });
                    }, <?php echo $time_popup; ?>);
                });
            </script>

这是我的剧本。我点击关闭弹出窗口时尝试重置设置间隔功能。我使用了大胆的弹出窗口,尝试this,没有结果。

1 个答案:

答案 0 :(得分:0)

您必须将setInterval电话分配给变量,才能使用clearInterval重置该字段。

var timer = setInterval(function() {
    // Your stuff.
    clearInterval(timer);
});

来自docs you shared

  

clearInterval()方法清除使用setInterval()方法设置的计时器。

     

setInterval()返回的ID值用作clearInterval()方法的参数。