版权声明:盗版必究 https://blog.csdn.net/qq_36658051/article/details/89849469
html
<div ref={e => (this.scrollDom = e)}></div>
js
componentDidMount() {
if (this.scrollDom) {
this.scrollDom.addEventListener("scroll", () => {
this.onScroll(this);
});
}
}
componentWillUnmount() {
if (this.scrollDom) {
this.scrollDom.removeEventListener("scroll", () => {
this.onScroll(this);
});
}
}
onScroll() {
const { clientHeight, scrollHeight, scrollTop } = this.scrollDom;
const isBottom = clientHeight + scrollTop === scrollHeight;
console.log(clientHeight, scrollHeight, scrollTop, isBottom);
}
isBottom为true时滚动到底部