jQuery: Back to Top Button

By using the animate and scrollTop methods in jQuery you don’t need a plugin to create a simple scroll-to-top animation.

Changing the scrollTop value changes where you want the scrollbar to land. All you’re really doing is animating the body of the document throughout the course of 800 milliseconds until it scrolls to the top of the document.

<!DOCTYPE html>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
        <title>To The Top Page</title>      
            $('a.top').click(function (e) {
                $(document.body).animate({scrollTop: 0}, 800);
        <a class='top' href='#'>To the top</a>


Leave a comment

Leave a Reply