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

131
Vistas
React scroll animation flickery

I created a simple scroll animation to fill a vertical timeline based on the scrolling position. Link to working example My problem is that the animation is still quite flickery, especially on mobile devices. Is there any way to make the animation more smooth? I already tried to solve this with css transition, but that didn't work.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It’s simply because you keep changing the value instantly on scroll. I tried and made it smooth by adding a very simple css transition to App.css in the code:

* {
  transition: 150ms all;
}

Once it works, you can change the selector * to the vertical line element, because we dont want it applied to all elements right, this is only for demo.

Also another approach for this. I think by not changing height value all the time but when a certain difference is met.

For example change component to this code, maybe you can try it, at least on my PC it's smooth enough

let lastValue = 0;
function App() {
  useEffect(() => {
    const timeline = document.querySelector(".timeline");
    const timelineDraw = document.querySelector(".timeline__draw");
    const bodyRect = document.body.getBoundingClientRect();
    const timelineOffset = timeline.getBoundingClientRect().top - bodyRect.top;

    var moveIndicator = function () {
      var viewportHeight = window.innerHeight;
      var hasScrolled = window.pageYOffset;
      const scrolledFurther = hasScrolled - timelineOffset + viewportHeight / 4;
      lastValue = lastValue === 0 ? scrolledFurther:lastValue;
      if (scrolledFurther && scrolledFurther > 0) {
        if (scrolledFurther > timeline.clientHeight) {
          timelineDraw.style.height = `${timeline.clientHeight}px`;
          return;
        }
        if (Math.abs(lastValue - scrolledFurther) > 2){
          lastValue = scrolledFurther;
          timelineDraw.style.height = `${scrolledFurther}px`;
        }
        return;
      }

      timelineDraw.style.height = "0px";
    };
about 4 years ago · Juan Pablo Isaza 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