在页面内容很多的情况,添加按钮实现自动返回顶部的功能
1.首先,你需要一个返回顶部的按钮,一个div或者a
<div class="toTop" title="返回顶部">
</div>
.toTop {
width: 50px;
height: 50px;
background: url(../img/toTop.png) no-repeat;
background-size: 100%;
position: fixed;
right: 30px;
bottom: 80px;
z-index: 99;
&:hover{
cursor: pointer;
opacity: .85;
}
}
$(".toTop").click(function() {
$("html,body").animate({
"scrollTop": "0px"
}, "slow");
});