Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda