-1

I am successfully starting an animation upon mouseover, but cannot manage to stop it upon mouseleave:

Start animation:

var executed = false; // to execute only once on repeat hover
var startslider = {};

$('#imgBx').mouseover(function(){

if (!executed) { 
    var startslider = setInterval(function(){
    executed = true;  
    rotateSlide();
    }, 1000);
} // end if executed

}); // end mouseover

Stop animation:

$('#imgBx').mouseleave(function(){
    clearInterval(startslider);
});
rainerbrunotte
  • 907
  • 1
  • 17
  • 37

1 Answers1

1

You are re-declaring the global variable 'startslider'.

Remove the var from the variable in the mouseover event listener.

 startslider = setInterval(function(){
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
urchmaney
  • 618
  • 5
  • 7