我正在尝试构建一个有点 OOP 的 jQuery 插件。一切都很顺利,但我似乎无法正确实现开始/暂停功能。我有以下两个功能:
this.startAutoPlay = function() {
var interval = setInterval(function() {
obj.gotoNext();
}, config.timing);
};
this.stopAutoPlay = function() {
clearInterval(obj.startAutoPlay);
};
我只需要一种从 stopAutoPlay
函数中访问间隔变量的方法。
有什么指点吗?
最佳答案
您需要清除您设置的间隔。
this.interval;
this.startAutoPlay = function() {
obj.interval = setInterval(function() {
obj.gotoNext();
}, config.timing);
};
this.stopAutoPlay = function() {
clearInterval(obj.interval);
};
关于javascript - jQuery startInterval 和clearInterval 在不同的函数中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30319373/