+ 2

Why if I click the button the second time it doesn't work?

https://code.sololearn.com/WT7debW9ibKh/?ref=app

31st Jan 2021, 9:31 PM
RichardB
RichardB - avatar
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 ^^
31st Jan 2021, 10:21 PM
visph
visph - avatar
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"; }
31st Jan 2021, 9:39 PM
visph
visph - avatar
0
Thank you!
1st Feb 2021, 2:29 PM
RichardB
RichardB - avatar