Animation in Automatic Scroll by clicking on an Anchor

Asked

Viewed 49 times

0

Hello folks I’m having a question with animation automatic scrolling with the redirect to the Anchor in the Html on the same page I tried several alternatives here the site did not work. Among them using libraries Jquery.

In case I needed to redirect by clicking on <a href="#componente">Componente</a>

To

<div id="componente">Esse aqui é o componente</div>

Only with the scroll animation slowly descending

  • 1

    Tried for CSS using scroll-behavior: smooth;?

  • 1

    Thank you so much you helped me and kept me from spending another 10 hours cracking my head on this problem.

1 answer

0

Using Jquery you can do a function and call her:

Example:

rolar_para('#componente'); //chamada

function rolar_para(elemento) {
    $('html, body').animate({
        scrollTop: $(elemento).offset().top
    }, 1000);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.