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

419
Visualizações
This smooth scroll function is not working, despite of setting the correct target

Here is the code for the smooth scroll and I have correctly imported it from React library still it yeilds no result:

const scrollToNextSection = () => { 
  scroller.scrollTo("SecondSection", { smooth: true, duration: 1500 });
};

here is the image of the section being called

image

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I have did with native DOM method scrollIntoView

It may not be an efficient example but the scroll is smooth as expected

For better view see this code sandbox link - smooth scroll

  • used Ref's

const App = () => {
  const refOrange = React.useRef(null);
  const refBlue = React.useRef(null);

  function scrollToNode(node) {
    node.current.scrollIntoView({ behavior: "smooth" });
  }

  return (
    <div>
      <div
        ref={refBlue}
        onClick={() => scrollToNode(refOrange)}
        className="div1"
      >
        Click to smooth scroll to orange
      </div>
      <div
        ref={refOrange}
        onClick={() => scrollToNode(refBlue)}
        className="div2"
      >
        Click to smooth scroll to sky blue
      </div>
    </div>
  );
}

ReactDOM.render(<App/>,document.querySelector('#root'))
.App {
  font-family: sans-serif;
  text-align: center;
}

.div1 {
  height: 200px;
  background-color: aqua;
  margin-bottom: 30px;
}
.div2 {
  height: 200px;
  background-color: rgb(255, 72, 0);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.1/umd/react.production.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.1/umd/react-dom.production.min.js"></script>
    
    <div id="root"></div>

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