animationend event not firing

Jessica

I am trying to add an animationend event to an element, but the event doesn't get fired. What am I doing wrong, and how can I fix it?

JSFiddle

var btn = document.getElementById('btn');
var elem = document.getElementById('elem');
var timeOutFunc;

btn.addEventListener('click', function() {
  elem.classList.add('show');
  clearTimeout(timeOutFunc);
  timeOutFunc = setTimeout(function() {
    elem.classList.remove('show')
  }, 1000);
});


elem.addEventListener('animationend', function(e) {
  console.log('animation ended');
});
#elem {
  background-color: orange;
  width: 100px;
  height: 100px;
  opacity: 0;
  transition: opacity 500ms ease;
}
#elem.show {
  opacity: 1;
  transition: none;
}
<button id="btn">Press Me</button>
<div id="elem"></div>

Jessica

There are two separate animating events.

  1. animationend
  2. transitionend

When using the css transition use transitionend, and when using @keyframes/animation, use animationend.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related