T
T
TinaLee2022-01-26 13:35:03
JavaScript
TinaLee, 2022-01-26 13:35:03

How to make synchronous scroll in react?

Hi all! Can you help sync scroll react. Here is the code where two blocks scroll synchronously https://codesandbox.io/s/react-custom-scroll-sync-... . But I need one block to scroll synchronously with the main scroll window. I changed that code a little here: https://codesandbox.io/s/funny-rain-ditbv?file=/sr... . The result should be something like on this site https://alakel.kg/c

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Karo, 2022-01-26
@Zraza

1) In useEffect we add an event listener on the scroll of window
2) We read in the window.scrollY handler, write it wherever we want
3) Do not forget to remove the listener when unmounting the component (return to useEffect)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question