篇幅过长,总是不利于操作,返回顶部能更友好的操作。
1.html代码
<div style="display:none;" class="back-to" id="toolBackTop">
<a title="返回顶部" οnclick="window.scrollTo(0,0);return false;" href="#top" class="back-top">返回顶部</a>
</div>
2.css代码
.back-to {
bottom: 35px;
overflow: hidden;
position: fixed;
right: 10px;
width: 110px;
z-index: 999;
}
.back-to.back-top {
background: url("back-top.png") no-repeat scroll 0 0 transparent;
display: block;
float: right;
height: 50px;
margin-left: 10px;
outline: 0 none;
text-indent: -9999em;
width: 50px;
}
.back-to.back-top:hover {
background-position: -50px 0
}
3.jquery代码
$(document).ready(function () { var bt = $('#toolBackTop'); var sw = $(document.body)[0].clientWidth; var limitsw = (sw - 880) / 2 - 80; if (limitsw > 0){ limitsw = parseInt(limitsw); bt.css("right",limitsw); } $(window).scroll(function() { var st = $(window).scrollTop(); if(st > 30){ bt.show(); }else{ bt.hide(); } }); })
4.图片