我正在尝试为 React.js 实现无限滚动。一切工作正常,除了我希望能够使用窗口滚动条来激活无限滚动。目前的代码有 2 个滚动条(我只想要一个)。
代码来自 stackoverflow 回答这里,我阅读了他的完整答案,我尝试将高度设置为 100%,但这使得无限滚动不起作用。:Stackoverflow- 由 Aniket Jha 回答(最长的回答,有 4 票赞成)
当我以这种方式呈现时,会发生双滚动:
<div>
<First />
<div ref="iScroll" style={{ height: "100vh", overflow: "auto"}}>
<ul>
{this.displayItems()}
</ul>
{this.state.loadingState ? <p className="loading"> loading More
Items..</p> : ""}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)class Layout extends React.Component {
constructor(props) {
super(props);
this.state = {
items: 30,
loadingState: false
};
}
componentDidMount() {
this.refs.iScroll.addEventListener("scroll", () => {
if (this.refs.iScroll.scrollTop + this.refs.iScroll.clientHeight >= this.refs.iScroll.scrollHeight - 20){
this.loadMoreItems();
}
}); …Run Code Online (Sandbox Code Playgroud)