PASSWORD RESET

Your destination for complete Tech news

How to scroll page to bottom in Javascript?

1.15K 0
< 1 min read

To scroll to the bottom of a webpage using JavaScript, you can manipulate the scrollTop property of the window object or the scrollTo() method. Here are two common methods to achieve this:

  1. Using the scrollTop property:
window.scrollTop = document.body.scrollHeight;

2. Using the scrollTo() method:

window.scrollTo(0, document.body.scrollHeight);

Both of these methods will scroll the page to the bottom by setting the vertical scroll position to the height of the entire document.

Here’s a complete example using the scrollTo() method:

// Scroll to the bottom of the page
function scrollToBottom() {
  window.scrollTo(0, document.body.scrollHeight);
}

// Call the function to scroll to the bottom
scrollToBottom();

Make sure you call these functions after the page has finished loading or at a suitable point in your code where the document’s height has been properly calculated.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.