Reputation: 12025
I tried to get client height when I scroll page:
@HostListener('window:scroll', ['$event']) onScrollEvent($event) {
if ($event.scrollHeight - $event.scrollTop === $event.clientHeight) {
console.log('scrolled to the end');
}
});
I need to detect if user scrolled to the end of page
Upvotes: 3
Views: 2720
Reputation: 13993
I think you can do it like this (see this post for other solutions, and this article for this solution):
@HostListener("window:scroll") onWindowScroll() {
let scroll = window.pageYOffset ||
document.documentElement.scrollTop ||
document.body.scrollTop || 0;
const max = document.documentElement.scrollHeight -
document.documentElement.clientHeight;
if (scroll === max) {
alert('Bottom');
}
}
See the Stackblitz demo here
Upvotes: 3