var btn = document.getElementById('btn');
var timer = null;
btn.onclick = function () {
timer = window.setInterval(() => {
// document.documentElement.csrollTop = 0;
if (document.documentElement.scrollTop == 0) {
clearInterval(timer);
return
}
document.documentElement.scrollTop -= 20;
}, 5)
}
window.onmousewheel = function () {//鼠標滾輪事件
console.log(document.documentElement.scrollTop)
clearInterval(timer);
}
複製代碼