Skip to content

Instantly share code, notes, and snippets.

@Stanton
Created March 9, 2015 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stanton/73385d219ab27c1eee74 to your computer and use it in GitHub Desktop.
Save Stanton/73385d219ab27c1eee74 to your computer and use it in GitHub Desktop.
Add a class then remove it on animation or transition end
// 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