JS 部分
/*回顶部
*@method showLoading
*@for
*@param{string}target: 会顶部容器的选择器
*@return {void}
*/
function gotop(target) {
$(document).scroll(function() {
var scroH = $(document).scrollTop(); //滚动高度
if(scroH > 100) {
$(target).fadeIn(200);
}else {
$(target).fadeOut(200);
}
});
$(target).click(function() {
$('body,html').animate({
scrollTop: 0
}, 500);
return false;
});
}
HTML部分
<div class="gotop-articleDetail">
<img src="../imgs/gotop.png" alt="" class="img">
</div>
CSS部分
.gotop {
position: fixed;
width: 10.67vw;
height: 10.67vw;
background-color: #9ea8d2;
border-radius: 50%;
overflow: hidden;
opacity: 0.8;
right: 4.67vw;
bottom: 7.07vw;
box-sizing: border-box;
padding: 2.8vw;
display: none;
z-index: 1000;
}
.gotop-articleDetail {
position: fixed;
width: 10.67vw;
height: 10.67vw;
background-color: #9ea8d2;
border-radius: 50%;
overflow: hidden;
opacity: 0.8;
right: 4.67vw;
bottom: 20.07vw;
box-sizing: border-box;
padding: 2.8vw;
display: none;
}