I want to add and remove a CSS class n
times to show an animation, to show a effect n
times, like when you set animation-iteration-count
, the diffence is that here I have two animations, the second with delay.
My idea was to use setTimeout
, so I read this Stack Overflow post but I didn't get the expected results.
Here is a snippet - and a JSfiddle - with the animation (showing once)
$('button').click(function(){
$('div').addClass('a');
$(this).attr('disabled','true').text('Started');
setTimeout(function(){
$('div').removeClass('a');
$('button').removeAttr('disabled').text('Finished | Again');
},6000);
});
div {
width: 100px; height: 100px; background: red;
}
.a {
animation: a 2s linear, b 2s 2s linear;
}
@keyframes a {
from { background: red; }
to { background: blue; }
}
@keyframes b {
from { background: blue; }
to { background: black; }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div></div>
<button>Start</button>