Skip to content

Instantly share code, notes, and snippets.

@tborychowski
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tborychowski/9131555 to your computer and use it in GitHub Desktop.
Save tborychowski/9131555 to your computer and use it in GitHub Desktop.
JS :: detect css transition end
/* From Modernizr */
function whichTransitionEvent() {
var el = document.createElement('fakeelement'), t,
transitions = {
'transition': 'transitionend',
'OTransition': 'oTransitionEnd',
'MozTransition': 'transitionend',
'WebkitTransition': 'webkitTransitionEnd',
'MsTransition': 'msTransitionEnd'
};
for (t in transitions) if (typeof el.style[t] !== 'undefined') return transitions[t];
}
/* Listen for a transition end event! */
var transitionEvent = whichTransitionEvent();
if (transitionEvent) e.addEventListener(transitionEvent, function () {
console.log('Transition complete!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment