React监听滚动

    componentDidMount() {
        const scrollDom = document.querySelectorAll('.q1-home')[0];
        scrollDom.addEventListener('scroll', this.handleScroll.bind(this));
    }

    handleScroll(event) {
        const srcElement = event.srcElement;
        const scrollTop = srcElement.scrollTop;
        if (scrollTop >= 200) {
           // 处理
        }
    }

 
    componentWillUnmount() {
        const scrollDom = document.querySelectorAll('.q1-home')[0];
        scrollDom.removeEventListener('scroll', this.handleScroll.bind(this));
    }

  

posted @ 2021-01-21 16:38  文学少女  阅读(310)  评论(0编辑  收藏  举报