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

192
Visualizações
Anchor links jump to accurate position after images are loaded

Similar to this post, my case doesn't use React Router or jQuery. It's just a single page and vertically long. As for the title, anchor links don't jump to the accurate position since the images are not loaded and cannot calculate the precise location. I found a solution and tried as below, but not working. How can I solve it?

UPDATE: As in the comment, setting image sizes didn't work either.

export const useScrollToLocation = () => {
const scrolledRef = useRef(false)
const { hash } = useLocation()
const hashRef = useRef(hash)

useEffect(() => {
    if (hash) {
        // We want to reset if the hash has changed
        if (hashRef.current !== hash) {
            hashRef.current = hash
            scrolledRef.current = false
        }

        // only attempt to scroll if we haven't yet (this could have just reset above if hash changed)
        if (!scrolledRef.current) {
            const id = hash.replace('#', '')
            const element = document.getElementById(id)
            if (element) {
                element.scrollIntoView({ behavior: 'smooth' })
                scrolledRef.current = true
            }
        }
    }
})

}

function App() {
    return (
        <>
            <useScrollToLocation>
                <Navigation />   
                <Hero />
                <Concept />
                <Shop />
                <Footer />
            </useScrollToLocation>
        </>
    )
}

export default App
about 4 years ago · Juan Pablo Isaza
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