0

How can I write a function that undoes the action after a few seconds? I am adding a class to an element with the purpose to create a short animation. I know I can set the animation time with css, but how do I remove the class after a few seconds? Should I create another animation setTimeout()?

Here is my code:

const copyAnimation = (item) => {
    item.classList.add('copied');
};
copyTextArea.addEventListener('click', () => {
  copyAnimation(clonedCode);
});
Mark Nunes
  • 827
  • 10
  • 23

2 Answers2

1

like this?

const copyAnimation = (item) => {
    item.classList.add('copied');
    setTimeout(function(){  item.classList.remove('copied'); }, 3000);
};
copyTextArea.addEventListener('click', () => {
  copyAnimation(clonedCode);
});
suresh bambhaniya
  • 1,687
  • 1
  • 10
  • 20
0

We can go with this =>

 setTimeout(
         function() 
        {
          $(this).removeClass("loader-input");
         }, 3000
);