var getTop = document.getElementById("get-top"); var head = document.getElementById("head"); getTop.onclick = function () { var time = setInterval(function () { document.body.scrollTop = document.body.scrollTop - 50; if (document.body.scrollTop === 0) { clearInterval(time); } }, 1); };
链接:https://segmentfault.com/q/1010000003855799