错误演示

btn.onclick = function (){
   //var time1 = (new Date()).getTime();//应该放到这里
    // 要慢慢的上去,就要加定时器 setInterval()
timer = setInterval(function (){
     
    var time1 = (new Date()).getTime();
//获取滚动条顶部到浏览器顶部的距离
var osTop = document.documentElement.scrollTop || document.body.scrollTop;
var ispeed = Math.floor(osTop / 5);
//让获取滚动条顶部到浏览器顶部的距离减等于200(就是不断减少到200)
document.documentElement.scrollTop = document.body.scrollTop = osTop - ispeed;
if(osTop == 0){
clearInterval(timer);
var time2 = (new Date()).getTime();
var dis = time2 -time1;
console.log(time1);
console.log(time2);
console.log(dis); // time1 和 time2 是相同
        }
},30);
}
原文地址:https://www.cnblogs.com/fdxxiaobai/p/7712886.html