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

130
Views
Quiero iniciar la función JS cuando me desplazo

Tengo un sitio web de una página con una sección para una barra de progreso. Tengo una función para animación y todo eso, y sé cómo iniciarla cuando se carga la página. Pero no sé cómo iniciarlo cuando me desplazo a esa sección.

Código JS:

 window.onload = function() { move(); }; var i = 0; function move() { if (i == 0) { i = 1; var elem = document.getElementById("myBar"); var width = 1; var id = setInterval(frame, 10); function frame() { if (width >= 95) { clearInterval(id); i = 0; } else { width++; elem.style.width = width + "%"; } } } }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Si desea activar el desplazamiento, puede hacerlo a través de jquery.

 $(element).scroll(() ={ function () }

Pero si desea animar en el desplazamiento, le aconsejo que use una biblioteca llamada Gsap. Busque en el documento scrollTrogger.

about 4 years ago · Juan Pablo Isaza Report

0

Simplemente use el evento de desplazamiento en todo el documento:

 document.addEventListener('scroll', function(e) { move(); }); var i = 0; function move() { if (i == 0) { i = 1; var elem = document.getElementById("myBar"); var width = 1; var id = setInterval(frame, 10); function frame() { if (width >= 95) { clearInterval(id); i = 0; } else { width++; elem.style.width = width + "%"; } } } }
 <div style="height:1000px;width:100%;"> <div style="height:200px">padding</div> <div id="myBar" style="background:green;">my bar</div> </div>

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!