html代码:

<button style="position: fixed;right: 30px;bottom:20px" id="back" onclick="back()">返回顶部</button>

javascript代码:

for(var i = 0; i < 100; i++){
  document.write("<li>" + i + "</li>");
}
function back(){
  var back = document.getElementById("back");
  var iSpeed = 40;
  var time = setInterval(function(){
    var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
    if(scrollTop > 0){
      document.body.scrollTop = document.documentElement.scrollTop =scrollTop/3 - iSpeed;
    }else{
      clearInterval(time);
    }
  },100)
}