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

148
Visualizações
Scroll to an element when clicking a button

I want to scroll to a div element when I click a button. But unfortunately the scroll isn't working. But my console.log()

I read this Scroll to the top of the page after render in react.js and this How to scroll to an element?

import React, { useEffect, useState, useRef } from 'react'

function TeamOld() {
    const myRef = useRef(null)

    return (
        <div>
                <button class="button is-primary is-outlined mr-4 mb-2" onClick={() => {myRef.current.scrollTo(0, 0); console.log("Test")}}>Click me</button>
            ...
            <div className="" style={{ width: "100%" }} ref={myRef}>
            </div>
        </div>
    )
}
export default TeamOld
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The function you are looking for is scrollIntoView (https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) scrollTo is used to scroll the element itself (assuming you have scrollbars inside your 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