+ 2
Why if I click the button the second time it doesn't work?
3 Answers
+ 2
my previous post was answering your initial question (why animation works only once)...
as you've edited your question, here's my second answer:
button click works only once, because you must remove the animation property before applying it another time...
simple fix:
function startAnimation() {
ovale1.style.animation = ovale2.style.animation = "";
setTimeout(function() {
ovale1.style.animation="oval1 1s 4 linear";
ovale2.style.animation="oval2 1s 4 linear";
},50);
}
better fix would be to make use of 'animationend' event handlers to reset the animation property ^^
0
function startAnimation() {
ovale1.style.animation="oval1 1s 4 linear";
ovale1.style.animationIterationCount = "infinite";
ovale2.style.animation="oval2 1s 4 linear";
ovale2.style.animationIterationCount = "infinite";
}
0
Thank you!