jQuery slide to the top of the page

28.Jun.2010

If you want to have nice, “go to top” button with sliding to top effect on your webpage, just copy following code:

1
2
3
<a onclick="jQuery('html, body').animate( { scrollTop: 0 }, 'slow' );"  href="javascript:void(0);">
	Go to top
</a>

If you would like to call slide “go to top” from your javaScript function, just use:

1
jQuery('html, body').animate( { scrollTop: 0 }, 'slow' );

and don’t forget to include your jQuery library.