Skip to content

Instantly share code, notes, and snippets.

@carlohcs
Created March 17, 2019 00:19
Show Gist options
  • Save carlohcs/a0868d287fe7a36e0c6f445bf4a1f5b2 to your computer and use it in GitHub Desktop.
Save carlohcs/a0868d287fe7a36e0c6f445bf4a1f5b2 to your computer and use it in GitHub Desktop.
Check when the animation is finished
// https://davidwalsh.name/css-animation-callback
/* From Modernizr */
function whichAnimationEvent() {
var t;
var el = document.createElement('fakeelement');
var animations = {
'animation': 'animationend',
'WebkitAnimation': 'webkitTransitionEnd'
}
// 'animationend'
// 'oanimationend'
// 'webkitAnimationEnd'
// 'MSAnimationEnd'
for (t in animations) {
if (el.style[t] !== undefined) {
return animations[t];
}
}
}
var animationEvent = whichAnimationEvent();
const
onAnimationEnd = function (el, fn) {
animationEvent && el.addEventListener(animationEvent, function() {
fn();
});
};
export default onAnimationEnd;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment