Jquery Scroll to Top With Animation

I believe this will be the simplest way of doing it. These days almost every website provides a top button so the end user can quickly go to the top of the web page. Here is the code

HTML Code

<a id="top"  onclick="topFunction();" style="display: block; cursor: pointer;">Go to Top</a>

And the following function with one line jquery code.

function topFunction()
{
$("html, body").animate({ scrollTop: 0 }, "slow"); //jquery animate method.
}

Leave a Reply

Your email address will not be published. Required fields are marked *