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

216
Visualizações
How to jump to top of page when routing WITHOUT using scroll?

I'm building a React application where I have footer links that when clicked, take the user to the bottom of whatever page they're clicking. I want to change it so that when these links are clicked, the user is automatically taken to the top of the new page.

I already tried a solution of automatically scrolling to the top of the page, which WORKS, but the issue is that I have smooth scrolling set for my website because I have some buttons that scroll to certain parts of the page clicked, and I want that animation to be smooth. However, for this particular function, I don't want smooth scroll because I don't want the user to see that they were taken to the bottom of a page then scrolled up.

This is my current code:

useEffect(() => {
    window.scrollTo(0, 0)
}, [])

Is there any way I can accomplish this without using scroll so that I can avoid having to display the smooth scrolling behavior?

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

0

You can try adding behaviour as instant in scrollTo function and do let me know if it works

useEffect(() => {
     window.scrollTo({
      top: 0,
      left: 0,
      behavior: "instant"
    });
}, [])
about 4 years ago · Juan Pablo Isaza Relatório

0

window.scrollTo({
  top: 0,
  left: 0,
  behavior: 'auto'
});

Should hopefully remove the smooth action.

about 4 years ago · Juan Pablo Isaza Relatório

0

document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera

document.body.scrollTop = 0; // For Safari
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