版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_41229582/article/details/82017838
html:
<div class="gallery">
<img src="images/zhizhen.png" alt="">
</div>
css:
.gallery
{ width: 60px; height: 60px; position: fixed; z-index: 10; bottom: 60px; right: 20px;display:none; }
.gallery
img{ width: 60px; height: 60px; }
jQuery:
function rightBar() {
$(window).scroll(function () {
var scroll_top = $(document).scrollTop();
console.log(scroll_top)
if (scroll_top > 230) { //当向下滚动230px时,出现返回顶部链接
$(".gallery").show(300);
} else {
$(".gallery").hide(300);
}
});
$(".gallery").click(function () {
$("html,body").animate({scrollTop:0}, 500);
});
}
rightBar();