You need to use the scroll event of the monitoring page. After struggling for a long time, I finally realized it. I wrote it and shared it with everyone. I hope you can leave me a message if you have a better way to do it, thank you��
export class Example extends Component{ scrollHandler = this.handleScroll.bind(this); componentDidMount() { window.addEventListener('scroll', this.scrollHandler); } _handleScroll(scrollTop) { console.log(scrollTop) //滚动条距离页面的高度 } } handleScroll(event) { let scrollTop = event.srcElement.body.scrollTop; this._handleScroll(scrollTop); } }
The above is the detailed content of How to implement ReactJS to listen to page scroll events. For more information, please follow other related articles on the PHP Chinese website!