Scroll to the top of the page using jQuery
In this tutorial, we are going to see how to scroll to the top of the page using jQuery. When a website has a lot of data on one page, the user may want to see the main content, i.e. the top of the page without scrolling, for this you can use jQuery.
Script : Scroll to the top of the page using jQuery
<html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script> <script> $(function () { $('#top').click(function () { $('html, body').animate({ scrollTop: '0px' }, 1500); return false; }); }); </script> </head> <body> <center> <p>Scroll up the page</p> <a id="top" href="#">Click here</a> </center> </body> </html>
Result |
---|
Scroll up the page Click here |