How to make the scroll start at the bottom of the page?

Asked

Viewed 243 times

-1

Hi, I have to make a site that starts from the bottom up but I can’t get the scroll to start at the bottom of the page.

That’s the script I’m using:

$(function scroll() {
    // scroll all the way down
    $('html').scrollTop($(document).height() - $(window).height()); 
})

The problem is that the scroll starts 600px above the bottom of the page, it started after I did the integration of it to the Standard

  • But with the code that posted the page is already rendered at the end of it. For you to test just put in css a height of 1500px for example in html, which you will see!

  • then I put the full width of the page that gives, 5615px only it gets about 600px up at the bottom

1 answer

1


You can use the method window.scrollTo to scroll the full height of the body.

Syntax: window.scrollTo(eixoX, eixoY)

$(function scroll() {
    window.scrollTo(0, document.body.scrollHeight);
})

The scrollHeight, according to the MDN:

The value of the scrollHeight is equal to the minimum height of the element would require to fit in all content on the viewport without using a bar vertical-scrolling.

  • vlw guy worked out

Browser other questions tagged

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