Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!