Home > Web Front-end > JS Tutorial > body text

How to implement ReactJS to listen to page scroll events

一个新手
Release: 2017-09-27 09:46:30
Original
5839 people have browsed it

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);
    }
}
Copy after login

How to implement ReactJS to listen to page scroll events

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template