Skip to content

Instantly share code, notes, and snippets.

@Rob-ot
Created December 14, 2011 17:49
Show Gist options
  • Save Rob-ot/1477647 to your computer and use it in GitHub Desktop.
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
// 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