let delay = 800; let pageHeight = 500; let preNow = newDate(); let el = document.getElementById('demo'); let scrollTop = el.scrollTop; el.addEventListener('scroll', myFunction);
functionmyFunction(e) { //节流计时器 let now = newDate(); if (now - preNow > delay) { preNow = now; if (el.scrollTop > scrollTop) { el.scrollTop += pageHeight; } else { if (el.scrollTop < scrollTop) { el.scrollTop -= pageHeight; } } scrollTop = el.scrollTop; } else { el.scrollTop = scrollTop; } }