<style>
*{
margin: 0;
padding: 0;
}
.content{
100%;
height: 100%;
overflow-y: scroll;
}
#box{
100%;
height: 3000px;
}
#btn{
150px;
height: 50px;
position: fixed;
bottom: 15px;
right: 15px;
cursor: pointer;
letter-spacing: 3px;
border-radius: 15px;
background-color: #f09;
text-align: center;
line-height: 50px;
font-size: 26px;
color: wheat;
}
</style>
<body>
<div class="content">
<div id="box"></div>
<div id="btn">回到顶部</div>
</div>
</body>
<script>
var btn = document.getElementById('btn')
var top = document.documentElement.scrollTop||document.body.scrollTop
window.onscroll = function(){
console.log(top)
}
btn.onclick = function(){
window.scrollTo(0,0)
}
</script>