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

87
Views
ReactJS - Get two divs two follow each others scrolling

I have two divs one is master and the other one is slave, I would like slave and master to follow each others scrolling.

master will always have the same width and height but slave can have any width and any height.

Problem: when I start scrolling it triggers an infinite loop because I'm using two useEffects to look at each others scroll percentage and update scrolling accordingly.

Sandbox: https://codesandbox.io/s/xenodochial-feather-3teev?file=/src/App.js

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I figured it out, using useEffect hooks was a mistake, because when one position changes the other will as well and this caused an infinite loop. I simply used the onScroll prop and selected the parent node and then the other div within the parent and modified the scroll position that way.

Easiest way to understand is to look at the code: https://codesandbox.io/s/react-js-scroll-sync-ee9wb

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