Created
March 9, 2015 08:34
-
-
Save Stanton/73385d219ab27c1eee74 to your computer and use it in GitHub Desktop.
Add a class then remove it on animation or transition end
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
// Assume .foo triggers a CSS animation, or a transition and that we wish to | |
// remove the .foo class when the animation completes. | |
// | |
// Useful for declarative animation class names like .shake | |
// on animation end | |
var animationEnd = 'webkitAnimationEnd oanimationend oAnimationEnd msAnimationEnd animationend'; | |
$('.foo') | |
.addClass('bar') | |
.one(animationEnd, function() { | |
$(this).removeClass('bar'); | |
}); | |
// on transition end | |
var transitionEnd = 'webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend'; | |
$('.foo') | |
.addClass('bar') | |
.one(transitionEnd, function() { | |
$(this).removeClass('bar'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment