Skip to content

Instantly share code, notes, and snippets.

@cameronbaney
Last active August 29, 2015 14:05
Show Gist options
  • Save cameronbaney/dc367971794dfcd9da54 to your computer and use it in GitHub Desktop.
Save cameronbaney/dc367971794dfcd9da54 to your computer and use it in GitHub Desktop.
Transition and Animation end with Modernizr
// Required Modernizr.prefixed()
// Animation callback
var animEndEventNames = {
'WebkitAnimation' : 'webkitAnimationEnd',// Saf 6, Android Browser
'MozTAnimation' : 'animationend', // only for FF < 15
'animation' : 'animationend' // IE10, Opera, Chrome, FF 15+, Saf 7+
},
animEndEventName = animEndEventNames[ Modernizr.prefixed('animation') ];
// Transition callback
var transEndEventNames = {
'WebkitTransition' : 'webkitTransitionEnd',// Saf 6, Android Browser
'MozTransition' : 'transitionend', // only for FF < 15
'transition' : 'transitionend' // IE10, Opera, Chrome, FF 15+, Saf 7+
},
transEndEventName = transEndEventNames[ Modernizr.prefixed('transition') ];
// Check if browser supports transitions
if(Modernizr.csstransitions) {
// Bind event to element to fire after transition
$(element).one(transEndEventName,function(){
elementTransitionCallback();
});
} else {
// If the browser doesn't support transitions, just fire the callback
elementTransitionCallback();
}
function elementTransitionCallback(){
// Do stuff
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment