Last active
August 29, 2015 14:05
-
-
Save matkl/fb2087c5754054d6347e to your computer and use it in GitHub Desktop.
Cross browser animate function for animate.css - Vanilla JavaScript. IE10+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function animate(element, animation) { | |
var eventNames = [ | |
'animationend', | |
'webkitAnimationEnd', | |
'MSAnimationEnd', | |
'oAnimationEnd' | |
]; | |
var listeners = []; | |
element.classList.add('animated'); | |
element.classList.add(animation); | |
eventNames.forEach(function(eventName) { | |
listeners.push(element.addEventListener(eventName, function() { | |
listeners.forEach(function(listener) { | |
element.removeEventListener(eventName, listener); | |
}); | |
element.classList.remove('animated'); | |
element.classList.remove(animation); | |
})); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use https://github.com/eligrey/classList.js polyfill for IE9.