You have two immediate possibilites:
1)
Use a setTimeout
function that fires after the animation is complete. To achieve this you should know how long the animation duration is:
$('.class').click(function() {
var animDuration = 1000; //ms of the animation duration
$(this).addClass("animate");
setTimeout(function(){
$(this).removeClass("animate");
}, animDuration);
});
2) A better solution is to add an eventListener on animationend webkitAnimationEnd oAnimationEnd MSAnimationEnd
that fires whenever the animation is actually complete. For this approach you do not need to know the duration of the animation.
EDIT: from adeneo
and also some code taken from here:
$('.class').click(function() {
var animDuration = 1000; //ms of the animation duration
$(this).addClass("animate");
$(this).bind('animationend webkitAnimationEnd oAnimationEnd MSAnimationEnd', function () {
$(this).removeClass('animate');
});
});
The above code does almost what you say, "gets the duration dynamically". What it really does is listening for an event that fires when the animation is complete / finished. The reason for the multiple event listeners is because of browser compatibility, each browser fires its own event. (oAnimationEnd = Opera, MSAnimationEnd = IE etc)
Thanks: https://coderwall.com/p/hn7gsg