如何在事件点击弹出窗口时重置setInterval函数关闭 [英] How to reset setInterval function on event click on popup close

查看:134
本文介绍了如何在事件点击弹出窗口时重置setInterval函数关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是我的脚本.单击关闭弹出窗口时,我尝试重置设置间隔功能.我使用的是弹出式窗口,请尝试使用,没有结果.

This is my script. I try to reset set interval function, when click close to popup. I use magnific popup, try with this, without result.

推荐答案

您必须将setInterval调用分配给变量,才能使用clearInterval重置它.

You have to assign your setInterval call to a variable to be able to reset it with clearInterval.

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

您共享的文档:

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

The clearInterval() method clears a timer set with the setInterval() method.

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

The ID value returned by setInterval() is used as the parameter for the clearInterval() method.

这篇关于如何在事件点击弹出窗口时重置setInterval函数关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆