Skip to content

Instantly share code, notes, and snippets.

@cointilt
Created May 8, 2014 14:37
Show Gist options
  • Save cointilt/c4cda1400420a420f623 to your computer and use it in GitHub Desktop.
Save cointilt/c4cda1400420a420f623 to your computer and use it in GitHub Desktop.
Detect Css Animation Completion
/* From Modernizr */
function whichTransitionEvent () {
var t,
el = document.createElement('fakeelement'),
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