VIEW ALL GALLERY LIGHTS

Monday, November 2, 2009

Create a "Back to top" button using Jquerry

if your web page is so long ,why don't you create a "back to top" button for your reader can back to top of page and see another content instead of scrolling page by themselves .
here is a small tip to create a "back to top" button . When user click on this button , page will be scrolled back to top slowly .
To make this ,follow some steps :
1,Login to your blogger . Go to layout .continue to edit HTML .
2,Add this code before ]]></b:skin> :
#backtotop {
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;
}


3,Add this code before </body> :

<a href="#" id="backtotop">Back 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'>

$(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>

you can change the text "back to top" with image if you want .
Sometime adding code to Blogger template may occur error ,so it's better to encode your code here and paste the result to template

Save your template .Ok ,you are done .
huy signature

No comments:

Post a Comment