Page Scroll to Top with jQuery

Posted by Sumank under jQuery category on | Points: 40 | Views : 1748
The code is very minimal but powerful,we can add a simple link or button.

<html xmlns="">
<head runat="server">
<title>Scroll to Top</title>

<script type='text/javascript'>
$(document).ready(function () {
//hide the "Scoll to Top" link
// Add click function to link for scroll the page on top
$("#toTop").click(function () {
$("html, body").animate({ scrollTop: 0 }, "slow");
// add function on scroll event of window to show and hide the link
$(window).scroll(function () {
if ($(window).scrollTop() == "0") {
else {

<style type="text/css">
background: none repeat scroll 0 0 #b6ff00;
border: 2px solid #ffffff;
bottom: 5px;
padding: 10px;
position: fixed;
right: 5px;
text-align: center;
width: 100px;

<form id="form1" runat="server">

Demo : Scroll to Top
Demo : Scroll to Top
Demo : Scroll to Top
<a href='#' id="GoTop">Go To Top</a>


Comments or Responses

Login to post response