3

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

POV
  • 11,293
  • 34
  • 107
  • 201

2 Answers2

3

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

jo_va
  • 13,504
  • 3
  • 23
  • 47
1

To get the height:

 var height = $window.innerHeight;
Eric Svitok
  • 792
  • 5
  • 11