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

165
Vistas
How to get maximum scroll position of an html element?

I want to create a parallax effect (moving a background image while scrolling but with a slower factor).

I have a wrapper div element with overflow auto and inside that div I have the background image and also some content, contentHeight > imageHeight > wrapperDivHeight.

<WrapperDiv with overflow auto>
  <Content ... />
  <BackgroundImage with position absolute />
<WrapperDiv />

My formula to position the image is the following

const imageTransformY = (100 * scrollY / (contentHeight - wrapperDivHeight) * (imageHeight - wrapperDivHeight) / imageHeight);
scrollY -> the scroll position (y-axis) of WrapperDiv component
contentHeight -> the height of Content component
wrapperDivHeight -> the height of WrapperDiv component
imageHeight -> the height of the BackgroundImage component
imageTransformY -> css property to position the image

and it is working as expected.

The thing is that I want to avoid using contentHeight because I retrieve it from the Content component. Instead I would like to get the maximum possible scroll of WrapperDiv component and maybe the scrollbar height in order to calculate the contentHeight from these values (contentHeight = maxScrollY + scrollHeight)

Is this possible ? Is this possible with react-use ?

about 4 years ago · Juan Pablo Isaza
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