0

JS button for CSS effect

I've created an animation with CSS and now I'd like to create a button that activates and deactivate the animation, but my knowledge of JS is very basic and I don't know how to do it. Anyone can help me?

31st Dec 2017, 12:25 PM
Diego
Diego - avatar
5 Answers
+ 2
As in the example, only with an animation instead of a red background. https://code.sololearn.com/W70fVBDrs6RN/?ref=app
31st Dec 2017, 12:57 PM
Viereck
Viereck - avatar
+ 2
The onclick function can give the tag which you want to animate a CSS class which includes the animation.
31st Dec 2017, 12:34 PM
Viereck
Viereck - avatar
+ 1
Yes it is possible too. Just do the same as you did with the button. You can take the ID of the div and do the same thing. I have updated the code so you can see it in action.
2nd Jan 2018, 12:50 PM
Viereck
Viereck - avatar
0
Thanks Alexander. And would it be possible to create a button to do the same but to a different html element? I mean, when I click the button, the animation applies to a <div> element (and sorry if I'm asking too much, but I'm really lost with this matter 😰)
2nd Jan 2018, 12:44 PM
Diego
Diego - avatar
0
Thanks!
2nd Jan 2018, 12:58 PM
Diego
Diego - avatar