let beforeScrollTop = 0;
function handleScroll () {
var scrollTop =
document.documentElement.scrollTop || document.body.scrollTop;
var clientHeight =
document.documentElement.clientHeight || document.body.clientHeight;
var scrollHeight =
document.documentElement.scrollHeight || document.body.scrollHeight;
if (scrollTop >= beforeScrollTop) {
if (scrollTop + clientHeight >= scrollHeight) {
console.log("滚动触底");
}
}
beforeScrollTop = scrollTop;
}
function throttle (f, w) {
let t = null;
return function () {
if (t) {
return;
}
t = setTimeout(() => {
f.apply(this, arguments);
t = null;
}, w);
};
}
window.onscroll = function () {
throttle(handleScroll(), 10000);
};