Skip to content
Advertisement

The animation only works with the first click of the button

I want to create simple text animation. When i click a button, text shifts from fully transparent to fully visible and reverts to transparent. I wrote code that does the animation but only once. The animation doesn’t work anymore every time when i click the button:

JavaScript
JavaScript
JavaScript

Advertisement

Answer

The animation does not repeat, because for animation to start CSS requires a frame when there was no class.

So, to solve this, you should delay adding class to the next frame

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement