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

162
Vistas
How can I apply scroll animation before top of viewport + calculate proper percentage?

I am trying to animate a path incrementally on scroll. I am following the techniques outlined here and here. I have my animation areas broken up into segments, and I am using waypoints to activate each segment. once activated (when the top of the segment hits the top of the viewport), the segment listens for the scroll event and then calculates the percentage of line to animate based on this snippet:

var scrollPercentage = rect.top / rect.height;

This seems to work ok, codepen is here. however I need this animation to start prior to the segment reaching the top of the viewport, say when it is 100px from the top. Also I need a way to calculate the percentage when rect.top is between 0 and 100. For some reason when I add a conditional statement it either a. doesn't fire or b. draws the path backwards:

    if (rect.top > 0 && rect.top < 100) {
      //unsure what how to calulate and trigger before
      //top of viewport
      //var scrollPercentage = ?;
    } else if (rect.top < 0 && rect.bottom > 0) {
      var scrollPercentage = rect.top / rect.height;
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You just need to add an offset to the rect top and bottom values. Then use that value in your comparison.

I've called it prestart.

var prestart = 100;
if ((rect.top - prestart) < 0 && (rect.bottom - prestart) > 0) {
  var scrollPercentage = (rect.top - prestart) / rect.height;
}
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