Created
March 17, 2019 00:19
-
-
Save carlohcs/a0868d287fe7a36e0c6f445bf4a1f5b2 to your computer and use it in GitHub Desktop.
Check when the animation is finished
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
// 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