Skip to content

Instantly share code, notes, and snippets.

@ifthenelse
Last active December 16, 2015 12:18
Show Gist options
  • Save ifthenelse/5433230 to your computer and use it in GitHub Desktop.
Save ifthenelse/5433230 to your computer and use it in GitHub Desktop.
Use modernizr to check CSS transitions events support: * 'WebkitTransition':'webkitTransitionEnd' (Chrome / Safari) * 'MozTransition':'transitionend' (Mozilla) * 'OTransition':'oTransitionEnd' (Opera) * 'transition':'transitionend' (Internet Explorer)
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];
}
}
}
// To launch the event
var transitionEnd = whichTransitionEvent();
element.addEventListener(transitionEnd, theFunctionToInvoke, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment