Wednesday, September 5, 2012

Create scroll top using jQuery


>> Using this code you can scroll to top. You must scroll down to see the effect.

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Untitled Document</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <script type="text/javascript">
        jQuery(document).ready(function(){
            jQuery('#top').click(function(){
                jQuery('html, body').animate({scrollTop: '0px'}, 2000);
            });
        });
        </script>
    </head>

    <body>
        <button id="top">Go Top</button>
    </body>
</html>