Detecting when user scrolls to bottom of div with React js

后端 未结 9 2221
悲哀的现实
悲哀的现实 2020-11-28 21:17

I have a website with different sections. I am using segment.io to track different actions on the page. How can I detect if a user has scrolled to the bottom of a div? I hav

9条回答
  •  广开言路
    2020-11-28 21:59

    I used follow in my code

    .modify-table-wrap {
        padding-top: 50px;
        height: 100%;
        overflow-y: scroll;
    }
    
    

    And add code in target js

        handleScroll = (event) => {
            const { limit, offset } = this.state
            const target = event.target
            if (target.scrollHeight - target.scrollTop === target.clientHeight) {
                this.setState({ offset: offset + limit }, this.fetchAPI)
            }
        }
        return (
                
    ...
    )

提交回复
热议问题