Last active
August 29, 2015 14:05
-
-
Save cameronbaney/dc367971794dfcd9da54 to your computer and use it in GitHub Desktop.
Transition and Animation end with Modernizr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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