jQuery不同函数中的startInterval和clearInterval
jQuery startInterval and clearInterval in different functions
我正在尝试构建一个有点面向对象的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);
};