@HostListener('window:scroll', ['$event'])
onWindowScroll() {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
console.log('reached bottom');
}
}
如上所述,这个代码正在运行,但它很多次都发生了,甚至还没有达到底部的最终结束。
如何检查滚动滚动到达底部的末尾?
答案 0 :(得分:1)
if (window.innerHeight + window.scrollY === document.body.scrollHeight) {
console.log('bottom');
}
我找到了。
答案 1 :(得分:1)
这对我有用。
import { HostListener } from '@angular/core';
@HostListener('window:scroll', ['$event'])
onWindowScroll(event) {
// 200 is the height from bottom from where you want to trigger the infintie scroll, can we zero to detect bottom of window
if ((document.body.clientHeight + window.scrollY + 200) >= document.body.scrollHeight) {
console.log('tiggred');
}
}