Skip to content

Instantly share code, notes, and snippets.

@travismillerweb
Created September 16, 2014 12:18
Show Gist options
  • Save travismillerweb/b3dfbc67e466b6129590 to your computer and use it in GitHub Desktop.
Save travismillerweb/b3dfbc67e466b6129590 to your computer and use it in GitHub Desktop.
JS - Detect Animation End
/*
Detect Animation End! (Thanks David Walsh)
Reference: http://davidwalsh.name/css-animation-callback
*/
/* From Modernizr */
function whichTransitionEvent(){
var t;
var el = document.createElement('fakeelement');
var transitions = {
'transition':'transitionend',
'OTransition':'oTransitionEnd',
'MozTransition':'transitionend',
'WebkitTransition':'webkitTransitionEnd'
}
for(t in transitions){
if( el.style[t] !== undefined ){
return transitions[t];
}
}
}
/* Listen for a transition! */
var transitionEvent = whichTransitionEvent();
transitionEvent && e.addEventListener(transitionEvent, function() {
console.log('Transition complete! This is the callback, no library needed!');
});
/*
The "whichTransitionEvent" can be swapped for "animation" instead of "transition" texts, as can the usage :)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment