Js点击回到顶部代码
点击回到顶部
Html
<!--回到顶部-->
<divtitle="返回顶部"></div>
Css
.backToTop{background:url(../images/back.png)no-repeat;width:25px;height:25px;text-indent:-99999px;display:none;position:fixed;_position:absolute;left:910px;_left:910px;bottom:10px;_bottom:"auto";cursor:pointer;}
Js
//点击回到顶部
(function(){
var$backToTopTxt="返回顶部",$backToTopEle=$('<div></div>').appendTo($("body"))
.text($backToTopTxt).attr("title",$backToTopTxt).click(function(){
$("html,body").animate({scrollTop:0},120);
}),$backToTopFun=function(){
varst=$(document).scrollTop(),winh=$(window).height();
(st>0)?$backToTopEle.show():$backToTopEle.hide();
//IE6下的定位
if(!window.XMLHttpRequest){
$backToTopEle.css("top",st+winh-166);
}
};
$(window).bind("scroll",$backToTopFun);
$(function(){$backToTopFun();});
})();