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

147
Views
Evite que la función de aceleración de javascript se repita si el usuario hace una pausa en el disparador

Quiero cambiar el tamaño de un encabezado cuando el usuario se desplaza, agregando o restando una clase. Pero, me estoy perdiendo algo. El siguiente script se dispara repetidamente, volviendo a agregar la clase, si un usuario se desplaza lentamente hacia abajo en la página hasta el punto de desplazamiento que activa la función. No importa la hora que configuré, el usuario aún se desplazó a esa ubicación y se detuvo, activando el script repetidamente. Probé con un antirrebote básico y no funcionó; tuve problemas similares.

Aquí está mi guión:

 let throttlePause; const throttle = (callback, time) => { if (throttlePause) return; throttlePause = true; setTimeout(() => { callback(); throttlePause = false; }, time); }; function scrollShrink() { document.getElementById('wrapper').classList.toggle('page-scrolled', window.pageYOffset >= 20); } // run through throttler window.addEventListener("scroll", () => { throttle(scrollShrink, 200); });
about 4 years ago · Santiago Trujillo
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!