对于JQuery(我想在当前项目中避免使用)和Angular1(我不明白)这个问题有答案。
答案 0 :(得分:0)
我们遇到了同样的问题。我们在构造函数中使用window.onscroll
:
window.onscroll = () => {
let status = 'not reached';
const windowHeight = 'innerHeight' in window ? window.innerHeight
: document.documentElement.offsetHeight;
const body = document.body, html = document.documentElement;
const docHeight = Math.max(body.scrollHeight,
body.offsetHeight, html.clientHeight,
html.scrollHeight, html.offsetHeight);
const windowBottom = windowHeight + window.pageYOffset;
if (windowBottom >= docHeight) {
status = 'bottom reached';
console.log('bottom reached');
const msg = 'Loading...';
console.log(msg);
this.limit = this.limit + 10;
// Limits added
// Bootom Reached here - Write your custom code here
}
return event;
}
不要忘记在ngOnDestroy()中取消window.onscroll
:
ngOnDestroy(): void {
window.onscroll = null;
}
或者(仅适用于手机),如果您使用的是锤子,则可以使用向上/向下滑动。检查http://hammerjs.github.io/recognizer-swipe/