我用Id引用了这个元素:
let infiniteScrollElement = document.getElementById('th-infinite-scroll-tracker');
当浏览器到达元素的底部时,我需要监听.
如何做到这一点?
我用Id引用了这个元素:
let infiniteScrollElement = document.getElementById('th-infinite-scroll-tracker');
当浏览器到达元素的底部时,我需要监听.
如何做到这一点?
我想你要做的就是检测卷轴的位置.
@HostListener("window:scroll", ["$event"])
onWindowScroll() {
//In chrome and some browser scroll is given to body tag
let pos = (document.documentElement.scrollTop || document.body.scrollTop) + document.documentElement.offsetHeight;
let max = document.documentElement.scrollHeight;
// pos/max will give you the distance between scroll bottom and and bottom of screen in percentage.
if(pos == max ) {
//Do your action here
}
}
也不要忘记从@angular/core导入HostListener.