Reputation: 123
@HostListener('window:scroll', ['$event'])
onWindowScroll() {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
console.log('reached bottom');
}
}
It is working of this code as above, but it occured many times even not reached exactly end of bottom.
How to check wheather scroll is reached to end of bottom?
Upvotes: 3
Views: 7668
Reputation: 157
This worked for me.
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, which can also be zero to detect bottom of window
if ((document.body.clientHeight + window.scrollY + 200) >= document.body.scrollHeight) {
console.log('triggred');
}
}
Upvotes: 5
Reputation: 123
if (window.innerHeight + window.scrollY === document.body.scrollHeight) {
console.log('bottom');
}
I found it.
Upvotes: 6