0

I have an animation using bodymovin that triggers when I mouseenter it and I'm trying to make it so that if I mouseover it again before the animation ends, it doesn't restart.

squareAnim.addEventListener('mouseenter', function(){
anim.removeEventListener('loopComplete', loopHandler);
anim.goToAndStop(1);
anim.play();

if(anim.play == true){
    anim.mouseenter == false;
} else {
    anim.mouseenter == true;
}
}); 

Am I getting the syntax wrong or is there a flaw in my logic?

phantomboogie
  • 113
  • 1
  • 7

1 Answers1

0

Just check if the animation is playing before you call goToAndStop() and play():

squareAnim.addEventListener('mouseenter', function(){
  anim.removeEventListener('loopComplete', loopHandler);

  if(anim.play !== true){
    anim.goToAndStop(1);
    anim.play();
  }
}); 
Constantin Groß
  • 10,719
  • 4
  • 24
  • 50