Last active
October 2, 2015 17:38
-
-
Save Rob-ot/2287067 to your computer and use it in GitHub Desktop.
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
| ;(function () { | |
| var Modernizr | |
| // run cb when the next animation is complate (or right away if there is no animation support) | |
| var cssTransitionEnd = function (cb) { | |
| var $self = $(this) | |
| var transEndEventNames = { | |
| 'WebkitTransition' : 'webkitTransitionEnd', | |
| 'MozTransition' : 'transitionend', | |
| 'OTransition' : 'oTransitionEnd', | |
| 'msTransition' : 'msTransitionEnd', // maybe? | |
| 'transition' : 'transitionEnd' | |
| } | |
| var transEndEventName = transEndEventNames[Modernizr.prefixed("transition")] | |
| function unbind () { | |
| $self.off(transEndEventName, animEnd) | |
| } | |
| // animations propogate so only cb if it was fired on this elem | |
| function animEnd (e) { | |
| if (e.target == e.currentTarget) { | |
| if (cb(e.originalEvent.propertyName) !== false) unbind() | |
| } | |
| } | |
| if (Modernizr.csstransitions) { | |
| $self.on(transEndEventName, animEnd) | |
| } | |
| else { | |
| // just run the cb now because the event will never be fired | |
| setTimeout(function () { | |
| cb("") | |
| }, 0) | |
| } | |
| return { | |
| unbind: unbind | |
| } | |
| } | |
| if (typeof define !== 'undefined' && define.amd) { | |
| // AMD | |
| define(['jquery', 'modernizr'], function ($, ModernizrDep) { | |
| Modernizr = ModernizrDep | |
| $.fn.cssTransitionEnd = cssTransitionEnd | |
| return $ | |
| }) | |
| } | |
| else { | |
| $.fn.cssTransitionEnd = cssTransitionEnd // old skool browser | |
| } | |
| }()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment