设置页面滚动到某一距离回到顶部
注意: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