如何清除所有间隔? [英] How do I clear all intervals?
本文介绍了如何清除所有间隔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用
varName = setInterval(function() { ... }, 1000);
在我正在编写的jquery插件中设置几个间隔,但是当插件是重新加载我需要清除这些间隔。我尝试将它们存储在变量中,如下所示:
to set a couple of intervals in a jquery plugin that I'm writing, but when the plugin is reloaded I need to clear those intervals. I tried storing them in variables, like this:
(function($){
$.mosaicSlider = function(el) {
var base = this;
var transitionInterval, mainInterval;
...
base.init = function() {
mainInterval = setInverval(function() { ... }, 1000);
}
base.grid = function() {
this.transition() = function() {
transitionInterval = setInterval(function(...) {
}
}
base.init();
我尝试在base.init()函数中杀死这些区间,如下所示:
And I tried killing those intervals in the base.init() function, like this:
clearInterval(transitionInterval);
clearInterval(mainInterval);
并且像这样:
window.oldSetInterval = window.setInterval;
window.setInterval = new function(func, interval) { }
推荐答案
你可以喜欢,
var interval_id = window.setInterval("", 9999); // Get a reference to the last
// interval +1
for (var i = 1; i < interval_id; i++)
window.clearInterval(i);
//for clearing all intervals
这篇关于如何清除所有间隔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文