I'm using setInterval to create a diy slideshow that starts on mouseenter using this tutorial : https://www.amideveloper.com/how-to-start-slideshow-on-hover-image-in-jquery/
It works fine, but I would like the slideshow to stop on mouseleave by using clearInterval.
I don't know what I'm doing wrong has my Interval is not cleared and the slideshow won't stop...
here is my code :
JQUERY
$(".fadeInOut > div:gt(0)").hide();
function change_div() {
$(".fadeInOut > div:first").fadeOut(0).next().fadeIn(0).end().appendTo(".fadeInOut");
}
$(".fadeInOut").mouseenter(function(){
myVar = setInterval(change_div, 600);
change_div();
});
$(".fadeInOut").mouseleave(function(){
clearInterval(myVar);
});
HTML
<div class="fadeInOut">
<div><img src="https://www.amideveloper.com/wp-content/themes/amideveloper/slide/slider-1.jpg"></div>
<div><img src="https://www.amideveloper.com/wp-content/themes/amideveloper/slide/slider-2.jpg"></div>
<div><img src="https://www.amideveloper.com/wp-content/themes/amideveloper/slide/slider-3.jpg"></div>
</div>
CSS
.fadeInOut > div {
position: absolute;
}
here's a link to a jsfidlle:
https://jsfiddle.net/0ysg3r67/
any help would be appreciated
myVarexplicitly in the right scope rather than implicitly making it a global.