整页滚动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
let delay = 800;
let pageHeight = 500;
let preNow = new Date();
let el = document.getElementById('demo');
let scrollTop = el.scrollTop;
el.addEventListener('scroll', myFunction);

function myFunction(e) {
//节流计时器
let now = new Date();
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;
}
}