1
I have the following code
var inter = setInterval(function(){
plusDivs(1);
}, 2500);
$(".mySlides").mouseenter(function(){
clearInterval(inter);
});
$(".mySlides").mouseleave(function(){
var inter = setInterval(function(){
plusDivs(1);
}, 2500);
console.log(inter);
});
In the code shown above, the variable inter
is supposed to be a loop that stops when the cursor enters the div
. When I reload the page, the loop starts fine, when I pass the cursor over it, for how it should be, when I remove the cursor from the div, it starts but then it passes again, it does not stop and withdraw again, 2 loops start at the same time.
The slideshow was based in this one
Is because you are redeclareting the inter variable in
mouseleave
– Valdeir Psr
And then how do I start the variable
inter
again?– I_like_trains
Try it this way:
$(".mySlides").mouseleave(function(){
 inter = setInterval(function(){
 plusDivs(1);
 }, 2500);
 console.log(inter);
});
without the var– Valdeir Psr
@Valdeirpsr That is, removed the
var
... I feel bad for being such a small mistake¯\_(ツ)_/¯
, publish the reply and I will accept.– I_like_trains