Created
July 29, 2014 20:21
-
-
Save devongovett/e2d927cf70e294071479 to your computer and use it in GitHub Desktop.
This file contains 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
var $ = require('jquery'); | |
var transitionEvents = 'transitionend msTransitionEnd webkitTransitionEnd'; | |
var visibilityEvents = 'visibilitychange mozvisibilitychange msvisibilitychange webkitvisibilitychange'; | |
/** | |
* Runs the given callback when the next transition on the selected element finishes. | |
* Sometimes the transitionend event doesn't fire when the page is in a | |
* background tab, so we also handle the page visibility events here too. | |
*/ | |
$.fn.transitionEnd = function(callback) { | |
var self = this; | |
var doc = $(document); | |
self.on(transitionEvents, transitionEnd); | |
doc.on(visibilityEvents, transitionEnd); | |
function transitionEnd() { | |
self.off(transitionEvents, transitionEnd); | |
doc.off(visibilityEvents, transitionEnd); | |
callback.call(self); | |
} | |
return this; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment