Skip to content

Instantly share code, notes, and snippets.

@gwendall
Created April 28, 2015 13:14
Show Gist options
  • Save gwendall/39368ad6dc1e3f87adaa to your computer and use it in GitHub Desktop.
Save gwendall/39368ad6dc1e3f87adaa to your computer and use it in GitHub Desktop.
jQuery animation end callback
/*
$(".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