HTML
<div id="top" class="top"></div>
CSS
.top{
position:fixed;
bottom:50px;
right:50px;
background:#000;
color:#fff;
width:60px;
height:60px;
line-height:60px;
text-align:center;
}
JS
top.onclikc=function(){
let step=100;
// 匀速向上滚动 每隔17MS向上滚动100px
let timer = setInterval(()=>{
if(document.documentElment.scrollTop>0){
document.documentElment.scrollTop = document.documentElment.scrollTop-step
}else{
document.documentElment.scrollTop=0;
clearInterval(timer)
}
},17)
}