设置页面滚动到某一距离回到顶部
注意:1、页面内有足够多的内容产生滚动,在页面底部添加链接,定义一个锚点回到顶部,初始时样式为不可见;
2、监听页面的滚动距离到某一个值时,锚点出现,点击回到顶部。
样式设置
<style>
#one {
width: 100%;
height: 50px;
background-color: gray;
}
#two {
width: 100px;
height: 100px;
line-height: 100px;
text-align: center;
background-color: bisque;
position: fixed;
top: 500px;
opacity: 0;
}
</style>
监听页面滚动,修改锚点样式
<script>
window.onload = function () {
var two = document.getElementById(

该博客介绍如何在页面滚动到特定距离时显示回到顶部的链接,并通过点击实现快速返回页面顶部。内容包括设置CSS样式使链接初始时不可见,监听页面滚动事件并在达到一定距离时改变链接的可见性,以及在页面底部添加锚点。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



