Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
Is there a way to calculate how long it will take for a smooth scroll to end

I want my animation to run after the screen has stopped scrolling in Javascript, otherwise the user won't be able to see it. Unfortunately, the speed of scrolling in chrome can vary a lot, and I don't know how to calculate the speed.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Instead of calculating the scroll duration, why not just start the animation once you detect the page is in the right scroll location? You can use window.scrollY to get the current vertical scroll of the page, and element.offsetTop to get the top position of the element.

You can make a function to check if the element is visible on the page with something like the following code.

function elementInScrolledView(element) {
    const pageTop = window.scrollY;
    const pageBottom = pageTop + window.innerHeight;

    const elementTop = element.offsetTop;
    const elementBottom = elementTop + element.offsetHeight;

    return ((elementBottom <= pageBottom) && (elementTop >= pageTop));
}

This code might need some edits if the element is taller than the window; you could compare just the tops of the elements?

You could start an interval checking each frame once the scrolling started until the function returned true, at which point you could clear the interval and start the animation.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda