标签:
function backTop() {
$(window).scroll(function () {
if ($(window).scrollTop() > 100) {
$("#topImg").fadeIn(1000);
}
else {
$("#topImg").fadeOut(1000);
}
});
//当点击跳转链接后,回到页面顶部位置
$("#topImg").click(function () {
//考虑到兼容性使用 body 和 html
$(‘body,html‘).animate({ scrollTop: 0 }, 800);
return false;
});
}
CSS 样式和HTML中的跳转图片设置如下:
#topImg{
position:fixed;
right:15px;
bottom:30px;
display:none;
}
<img id="topImg" src="../images/top.PNG" />
标签:
原文地址:http://www.cnblogs.com/yougmi/p/4224483.html