自动返回顶部的实现

在页面内容很多的情况,添加按钮实现自动返回顶部的功能

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");
});

猜你喜欢

转载自blog.csdn.net/WEIGUO19951107/article/details/78172374