简体   繁体   English

为什么 clearInterval 不清除我的 setInterval function? [等候接听]

[英]Why clearInterval doesn't clear my setInterval function? [on hold]

So i call a navigateRight function every 3 seconds.所以我每 3 秒调用一次 navigateRight function。

WrappingCarousel.prototype.startSlideShow = function() {
        var self = this;
        clearInterval(this.slideShowInterval);
        this.slideShowInterval = setInterval(function () {
            self.navigateRight(true);
        }, 3000);
    };


WrappingCarousel.prototype.navigateRight = function(notRestart) {
    if ($("#catalog").hasClass("screen0") && $("#catalog-content").is(":visible")) {
        clearInterval(this.startSlideShow); // -----> I CLEAR IT HERE.
    }
    if (this.index+1 >= this.items.length) { this.index = -1; }
    if (!notRestart) this.startSlideShow();
    return Carousel.prototype.navigateRight.call(this);
};

Inside function which calls every 3 seconds i have an condition, which should clear this interval, but it doesn't clear it at all.在每 3 秒调用一次的 function 内部,我有一个条件,应该清除这个间隔,但它根本没有清除它。

Please, try with clearInterval(this.slideShowInterval) inside the navigateRight function, which seems to be the right variable you used to store the value returned by the setInterval function, instead of clearInterval(this.startSlideShow) .请尝试在navigateRight function 中使用clearInterval(this.slideShowInterval) ,这似乎是您用来存储setInterval function 返回的值的正确变量,而不是clearInterval(this.startSlideShow)

More here:更多在这里:

https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval

https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearInterval https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearInterval

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM