Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

animate.css: repeating animations

I'm using animate.css for doing some animations. If an error occurs, the element should bounce:

$target.addClass('animated bounce');

That's working well. But if the user is doing the same thing, there won't be a second animation, as the classes are already added.

So I try to remove the classes after the animation like this:

$target.addClass('animated bounce');
setTimeout(function(){
    $target.removeClass('animated bounce');
}, 1000);

My question is, if this is how it should be done (I don't know how long the animation is exactly), or is there another solution for repeating animations?

like image 505
user3142695 Avatar asked Dec 07 '15 20:12

user3142695


People also ask

How do you stop an animation from looping in CSS?

The basics of pausing an animation The only way to truly pause an animation in CSS is to use the animation-play-state property with a paused value. In JavaScript, the property is “camelCased” as animationPlayState and set like this: element.

How do you rerun an animation in CSS?

Playing & pausing a CSS animation can be done by using the animation-play-state property. animation-play-state: paused pauses the animation, while animation-play-state: running starts playing the animation again.

Can I add 2 animation in CSS?

You can specify multiple animations--each with their own properties--with a comma. Save this answer.


1 Answers

You need to do this:

$('#target').removeClass().addClass('bounce animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
    $(this).removeClass();
});

$('#target') is in this case the ID of your element, change this to your needs.

like image 146
Franco Avatar answered Oct 20 '22 11:10

Franco