Si8 Si8 - 1 month ago 11
jQuery Question

How to cleartimeout a selected variable from multiple choices on hover

Fiddle: https://jsfiddle.net/b1Lsp3y3/

Script:

...
$(this).parent().mouseover(function () {
if (settings.pauseOnHover == 1) {
clearInterval(po);
}
}).mouseout(function () {
po = setInterval(function () { AutoSlide($(this)) }.bind(this), settings.timeoutSet);
});
...


The issue I am having is when hovering over any of the slider it doesn't pause that one but instead both sliders starts to act randomly.

How can I update my script so if I hover over the first slider, it pauses that one only and the second slider continues and if I hover over the second slider, it pause that one only and first slider continues from where it was paused from, and so forth.

Answer

You need to bind the mouseout callback function.

$(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
Comments