您可以
el.getBoundingClientRect().bottom用来检查底部是否已被查看
isBottom(el) { return el.getBoundingClientRect().bottom <= window.innerHeight;}componentDidMount() { document.addEventListener('scroll', this.trackScrolling);}componentWillUnmount() { document.removeEventListener('scroll', this.trackScrolling);}trackScrolling = () => { const wrappedElement = document.getElementById('header'); if (this.isBottom(wrappedElement)) { console.log('header bottom reached'); document.removeEventListener('scroll', this.trackScrolling); }};
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)