您的位置:首页 > 运维架构

HTML页面实现返回顶部效果 go to top

2020-02-02 14:26 991 查看

1、首先导入jQuery插件。

2、js代码:

$(window).scroll(function () {
if($(window).scrollTop()>=100) {
$(".backtop").fadeIn();
}else {

$(".backtop").fadeOut();
}
});

$(".backtop").click(function(event){
$('html,body').animate({scrollTop:0}, 500);
return false;
});

 

3、css代码:

a.backtop {
background: url("./sw/images/backtotop.png") no-repeat scroll center center rgba(0, 0, 0, 0);
bottom: 20px;
cursor: pointer;
display: none;
height: 70px;
position: fixed;
right: 20px;
text-indent: -9999px;
width: 70px;
z-index: 100;
}

 

4、页面代码:

<a class="backtop" >
<h6>返回顶部啊</h6>
</a>

 

转载于:https://www.cnblogs.com/tq03/p/3985502.html

  • 点赞
  • 收藏
  • 分享
  • 文章举报
aixian1969 发布了0 篇原创文章 · 获赞 0 · 访问量 338 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: