To blink an element in JavaScript, you can add and remove a CSS class with specific keyframe animation using JavaScript's DOM manipulation methods. Here's an example:
44 chars2 lines
106 chars10 lines
index.tsx239 chars11 lines
In the above code, we first define a CSS class .blink
that animates element to switch between visible and invisible states. Then, in JavaScript, we select the button element and define a function blink()
that adds the .blink
class to it using classList.add()
. After a 2 second timeout, we remove the class using classList.remove()
method.
Finally, we add an event listener to the button to call the blink()
function when it is clicked.
gistlibby LogSnag