fiddle :https://jsfiddle.net/b1Lsp3y3/
脚本:
...
$(this).parent().mouseover(function () {
if (settings.pauseOnHover == 1) {
clearInterval(po);
}
}).mouseout(function () {
po = setInterval(function () { AutoSlide($(this)) }.bind(this), settings.timeoutSet);
});
...
我遇到的问题是,当鼠标悬停在任何一个 slider 上时,它不会暂停那个 slider ,而是两个 slider 开始随机 Action 。
如何更新我的脚本,如果我将鼠标悬停在第一个 slider 上,它只暂停那个 slider ,第二个 slider 继续,如果我将鼠标悬停在第二个 slider 上,它只暂停那个 slider ,第一个 slider 从它原来的位置继续暂停,等等。
最佳答案
需要绑定(bind)mouseout回调函数。
$(this).parent().mouseover(function () {
if (settings.pauseOnHover == 1) {
clearInterval(po);
}
}).mouseout(function () {
po = setInterval(function () { AutoSlide($(this)) }.bind(this), settings.timeoutSet);
}.bind(this)); // <<-- TRY THIS
关于javascript - 如何在悬停时从多个选择中清除选定变量的超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40287940/