Advertisements

How To Create "Scroll to Top" button

Posted by Lasantha Bandara on May 19th, 2009 File Under : background, button, change template, widget1 Comment
Advertisements

Scroll to top button is very useful for bloggers if their have long blogs.To Add "scroll to top" button to your blog ,follow the steps below.

1.Log in to your dashboard--> layout- -> Edit HTML

2.Scroll down to where you see this:


]]></b:skin>

3.Now add below CSS code before  ]]></b:skin>  tag .


/* to top */
#toTop { width:100px;background:#F4FFBF;border:1px solid #ccc;text-align:center;padding:5px;position:fixed;bottom:10px;right:10px;cursor:pointer;color:#666;text-decoration:none; }

4.Now add below code  before  </body>  tag:


<a href="#" id="toTop">^ Scroll to Top</a>

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js' type='text/javascript'></script>
<script type='text/javascript'>
/*-----------------------
* jQuery Plugin: Scroll to Top
* by Craig Wilson, Ph.Creative (http://www.ph-creative.com)
* Bring to you by Zen from http://zenplate.blogspot.com
* Copyright (c) 2009 Ph.Creative Ltd.
* Description: Adds an unobtrusive "Scroll to Top" link to your page with smooth scrolling.
* For usage instructions and version updates to go http://blog.ph-creative.com/post/jquery-plugin-scroll-to-top.aspx
* Do not delete these infomation
* Version: 1.0, 12/03/2009
-----------------------*/

$(function(){$.fn.scrollToTop=function(){$(this).hide().removeAttr("href");if($(window).scrollTop()!="0"){$(this).fadeIn("slow")}var scrollDiv=$(this);$(window).scroll(function(){if($(window).scrollTop()=="0"){$(scrollDiv).fadeOut("slow")}else{$(scrollDiv).fadeIn("slow")}});$(this).click(function(){$("html, body").animate({scrollTop:0},"slow")})}});

$(function() {
$("#toTop").scrollToTop();
});
</script>

5.Now save your template and you are done.Look at the picture below.

File Under : background, button, change template, widget

One Response to “How To Create "Scroll to Top" button”

  1. Lahiru Udara says:

    My blog not properly displayed. bottom of blog page some html code display. why?

    /* to top */ #toTop { width:100px;background:#F4FFBF;border:1px solid #ccc;text-align:center;padding:5px;position:fixed;bottom:10px;right:10px;cursor:pointer;color:#666;text-decoration:none; }

Leave a Reply