How to detect scroll to bottom of html element

后端 未结 4 863
一生所求
一生所求 2020-12-02 11:42

I have this element that I\'m referencing by Id:

    let infiniteScrollElement = document.getElementById(\'th-infinite-scroll-tracker\');

I

4条回答
  •  [愿得一人]
    2020-12-02 11:48

    You could check whether the user has scrolled to the bottom or not in the below way...

    Html file

    ... ...

    typescript file

    import { Component, HostListener } from '@angular/core';
        ...
        ...
    @HostListener('scroll', ['$event'])
    onScroll(event: any) {
        // visible height + pixel scrolled >= total height 
        if (event.target.offsetHeight + event.target.scrollTop >= event.target.scrollHeight) {
          console.log("End");
        }
    }
    

提交回复
热议问题