Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to prevent button click while event still happening? Javascript

i try to find answer for my question on web but but I didn’t come across anything similar.

Is there any way in JAVASCRIPT to prevent same event triggering two time, while first trigger don’t finish all the job. I have some kind of spinning wheal and and I want to prevent the possibility of pressing the button until it turns a full circle, the time it takes to turn a full circle is 2s, but when the first spin is done I want button to work over and over again in the same way.

Here is my JAVASCRIPT code for that event.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

`let num = 0

  spin2.addEventListener('click', () => {
    num += 360
    linija.style.transform = `rotate(${num}deg)`
    linija.style.transition = "all 2s"
  })`

>Solution :

Use setTimeout to do something like that :

button.addEventListener('click', () => {
  if (buttonDisabled === false) {
    // Logic
    num += 360
    linija.style.transform = `rotate(${num}deg)`
    linija.style.transition = "all 2s"
    // Disable button
    buttonDisabled = true;
    button.textContent = 'Disabled';
    setTimeout(function() {
      buttonDisabled = false;
      button.textContent = 'Click me';
    }, 5000);
  }
});

Also, you should look at this : how to disable button for period and repeat that again (javaScript).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading