Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
clearIntervall no deja de desplazarse configurado con temporizador

Soy un novato de js, pero por lo que leí, usar clearInterval con la identificación devuelta previamente por setInterval debería restablecer el temporizador.

Al presionar un pedal, recibo un evento midi con un valor positivo y luego el mismo evento con un valor cero al soltar el pedal.
Usando el código a continuación, puedo ver que mi página se vuelve roja cuando se libera, pero la página sigue desplazándose. ¿Alguna idea de por qué?

 function handleMIDIMessage(event) { var scroll_id; if (event.data.length === 3) { if (event.data[0] == 176 && event.data[1] === 67) { if (event.data[2] > 0) { scroll_id = setInterval(function() { window.scrollBy({ top: 50, behaviour: "smooth" }); }, 1000); document.body.style.background = 'green'; } else { document.body.style.background = 'red'; clearInterval(scroll_id); } } } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe declarar el intervalo fuera para no seguir creando una nueva variable y perder la identificación. Probablemente también debería verificar para asegurarse de que no está creando más de un intervalo.

 //declare it so it is not overwritten var scroll_id; function handleMIDIMessage(event) { if (event.data.length === 3) { if (event.data[0] == 176 && event.data[1] === 67) { if (event.data[2] > 0) { // if we were defined before, cancel the last one if (scroll_id) window.clearInterval(scroll_id); scroll_id = setInterval(function() { window.scrollBy({ top: 50, behaviour: "smooth" }); }, 1000); document.body.style.background = 'green'; } else { document.body.style.background = 'red'; clearInterval(scroll_id); } } } }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!