Created
December 14, 2011 17:49
-
-
Save Rob-ot/1477647 to your computer and use it in GitHub Desktop.
jQuery plugin that uses modernizr to detect css3 transition support and listens for transitionEnd or calls back right away if transitions are not supported
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
// jQuery plugin that uses modernizr to detect css3 transition support and listens for transitionEnd or calls back right away if transitions are not supported | |
// basically send this a cb and it will be run on transitionEnd or right away if transitionEnd is not supported | |
jQuery.fn.cssTransitionEnd = function (cb) { | |
// lifted from http://www.modernizr.com/docs/ | |
var transEndEventNames = { | |
'WebkitTransition' : 'webkitTransitionEnd', | |
'MozTransition' : 'transitionend', | |
'OTransition' : 'oTransitionEnd', | |
'msTransition' : 'msTransitionEnd', // maybe? | |
'transition' : 'transitionEnd' | |
} | |
var transEndEventName = transEndEventNames[Modernizr.prefixed("transition")] | |
if (Modernizr.csstransitions) { | |
$(this).one(transEndEventName, function (e) { | |
cb() | |
}) | |
} | |
else { | |
// just run the cb now because the event will never be fired, run it async to be consistent | |
setTimeout(function () { | |
cb() | |
}, 0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment