Scrolltop after the page has already been loaded

Asked

Viewed 147 times

1

I want to scrollTop after I click on a button. Just not on the page I’m on but on the page that will open.

My HTML:

<a href="/clinicas" class="saibaMais cp margin-top-40 margin-bottom-25 f-left unidadesClick">
    <div class="saibaMaisText">saiba mais</div>
    <div class="saibaMaisHover">saiba mais</div>
</a>

And my Jquery:

$('.unidadesClick').click(function () {
  $('html, body').stop().animate({
   scrollTop: '620px'
   }, 700);
});

The way it is, it does Scrolltop on the same page. How do I make it work when I’m inside the a /clinics?

  • Like a #ancora?

  • No. When I click a, it opens the page and gives a Scrolltop.

  • Ah, like a #ancora with the smooth rolling?

  • This, it can be yes. What happens is that you are scrolling on the page before accessing the a.

1 answer

3


Make sure you are accessing a URL that contains /clinicas:

$(function(){
    //coloque este código onde quer que você tenha o código que verifica que o DOM está pronto
    if (window.location.toString().indexOf('/clinicas') > 0) {
        $('html, body').stop().animate({
             scrollTop: '620px'
        }, 700);
    }

});  

That should solve your problem.

Your jQuery is scrolling the page before accessing because that’s what’s written: by clicking on the element .unidadesClick, scrollTop no 620px do <body>, when you want it to scroll when we’re on the page /clinicas.

Browser other questions tagged

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