首页 > 解决方案 > clearInterval 不能从 setTimeout 内的间隔工作

问题描述

清除间隔不适用于我在 setTimeout() 中使用的间隔。

var $scroller;

setTimeout(function() {
    var div = jQuery('.module-content-slider');
    $scroller = setInterval(function(){
        /* interval function */
    }, 25)
}, 1000);

 clearInterval($scroller);

标签: javascriptsetintervalclearinterval

解决方案


在 1 秒(毫秒)后的 "" 内clearInterval运行之前的运行 - 有效地清除未设置的间隔。setIntervaltimeout1000$scroller


推荐阅读