constructor(props) {
super(props);
this.myRef = React.createRef();
}
<ul
ref={this.myRef}
onScroll={() => this._onScroll()}
className="scroll">
<li></ii>
<li></li>
</ul>
_onScroll = () => {
// 未滚动到底部
if (( this.myRef.current.scrollHeight - this.myRef.current.clientHeight ) > this.myRef.current.scrollTop) {
//未到底
} else {
//已到底部
this._getNewsData()
}
};
.scroll{
width: 100%;
display: flex;
flex-wrap: wrap;
height: calc(100vh - 76px - 123px - 85px);
overflow-y: auto;
overflow-x: hidden;
}
样式必须设置overflow 和 hidden