To auto scroll a page from top to bottom we can use scrollTop() and height() method in jquery.
In this method pass the document’s height in scrollTop method to scroll.
Example-1: Scroll without animation.
<!DOCTYPE html> <html> <head> <title>Scroll Automatically</title> <script src= </script> <!-- jQuery code to show the working of this method --> <script> $(document).ready(function() { $("button").click(function() { $(document).scrollTop($(document).height()); }); }); </script> <style> h1 { color: green; } </style> </head> <body> <center> <div> <!-- click on this button and see the change --> <button>Click Here!</button> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> </div> </center> </body> </html> |
chevron_right
filter_none
Output:
- Before:

- After:

Example-2: Scroll with animation.
<!DOCTYPE html> <html> <head> <title>Scroll Automatically</title> <script src= </script> <!-- jQuery code to show the working of this method --> <script> $(document).ready(function() { $("button").click(function() { $("html, body").animate({ scrollTop: $( 'html, body').get(0).scrollHeight }, 2000); }); }); </script> <style> h1 { color: green; } </style> </head> <body> <center> <div> <!-- click on this button and see the change --> <button>Click Here!</button> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> <h1>GeeksforGeeks</h1> </div> </center> </body> </html> |
chevron_right
filter_none
Output:
- Before:

- After:

Recommended Posts:
- How to scroll automatically to a particular element using JQuery?
- How to set textarea scroll bar to bottom as a default using JavaScript/jQuery ?
- Scroll to the top of the page using JavaScript/jQuery
- How to scroll the page up or down using anchor element in jQuery ?
- How to call a function automatically after waiting for some time using jQuery?
- Hide scroll bar, but while still being able to scroll using CSS
- How to set Bootstrap 4 scroll to the bottom of long sticky sidebar?
- CSS scroll-margin-bottom Property
- How to Adjust the Width of Input Field Automatically using JavaScript ?
- How to Automatically Close Alerts using Twitter Bootstrap ?
- How to like multiple posts on facebook news feed automatically using JavaScript ?
- How to display search result of another page on same page using ajax in JSP?
- How to create footer to stay at the bottom of a Web page?
- How to disable scroll to change number in <input type="number"> field using JavaScript/jQuery?
- How to scroll window using jQuery ?
- How to change style of elements on scroll using jQuery ?
- How to scroll to specific element using jQuery ?
- How to use Bootstrap modal for YouTube videos and play automatically ?
- How to automatically close all collapsible elements inside of the accordion when closing the accordion?
- How to automatically start a download in PHP ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

