加不加负号都试了一下,都不行,这是为什么呢
window.onload = function(){ var returnBtn = document.getElementById("returnTop"); var time = null; returnBtn.onclick = function(){ //获取滚动条到顶部的高度 setInterval(function(){ var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; //设置速度 向下取整 var ispeed = Math.floor(-scrollTop/10); document.documentElement.scrollTop = document.body.scrollTop = scrollTop + ispeed; if(scrollTop<=0){ clearInterval(time); } },10); } }