网站返回顶部功能

CSS:

  

#scrolltop {display:none; position:fixed; bottom:80px; left:51%; _position:absolute; _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight));
margin-left:480px; font-size:14px; text-align:center; color:#f00; cursor:pointer; height:48px;width:44px;background:url(../images/top.png) no-repeat -44px 0;}
#scrolltop:hover{border:0;padding:0;background:url(../images/top.png) no-repeat;}

 

Jquery:

<script type="text/javascript">
$(function () {
$(window).scroll(function () {
var top = $(window).scrollTop();
if (top > 500) {
$("#scrolltop").fadeIn();
} else {
$("#scrolltop").fadeOut();
}
});
$("#scrolltop").click(function () {
$("html,body").animate({ scrollTop: 0 });
});
});
</script>

页面内容:

<div id="scrolltop" style="display: none; "></div>

图片:

posted @ 2013-07-31 15:02  寻找幸福的起点  阅读(216)  评论(0编辑  收藏  举报