0

I am trying to make animated icon to be playable every time on hover instead of just once. But I cant make it work with mouseout There is my code:

<div class="shapeshifter" id='btn' style="background-image: 
url(sprite_60fps.svg) "></div>

<script>
document.getElementById('btn').addEventListener('mouseover', 
    function() {
    this.classList.add('play');
}); 

 </script>

1 Answers1

0

what you need is "restart css animation with js on mouse enter".

call this function on mouse enter:

function reset_animation() {
  var el = document.getElementById('btn');
  el.style.animation = 'none';
  el.offsetHeight; /* trigger reflow */
  el.style.animation = null; 
}

make sure don't use it on mouseover, use it on mouseenter.

(more info: Restart animation in CSS3: any better way than removing the element?)

yaya
  • 7,675
  • 1
  • 39
  • 38
  • I want animation to play just once on hover, and when I come back on in to repeat again once. When I do the iteration it repeats nonstop until I mouseleave – Валери К. Jun 04 '19 at 12:29