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

95
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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