Created
April 28, 2015 13:14
-
-
Save gwendall/39368ad6dc1e3f87adaa to your computer and use it in GitHub Desktop.
jQuery animation end callback
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
/* | |
$(".some-selector").onAnimationEnd(function(animationName) { | |
console.log(" Will be called when any of the show or hide animations end."); | |
}, ["show", "hide"]); | |
*/ | |
$.fn.onAnimationEnd = function(callback, animationName) { | |
var animations = ["animationend", "oAnimationEnd", "MSAnimationEnd", "webkitAnimationEnd"]; | |
$(document).delegate(this.selector, animations.join(" "), function(e) { | |
var ev = e.originalEvent || e | |
if (animationName && Object.prototype.toString.call(animationName) === "[object Array]" && animationName.indexOf(ev.animationName) === -1) return; | |
if (animationName && Object.prototype.toString.call(animationName) !== "[object Array]" && animationName !== ev.animationName) return; | |
callback && callback.apply(this, [ev.animationName]); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment