【发布时间】:2019-05-10 12:34:09
【问题描述】:
我找不到如何知道here 中的一个窗口组件是否滚动到底部。是否有一个属性告诉滚动相对于溢出的父级在哪里?
谢谢!
【问题讨论】:
我找不到如何知道here 中的一个窗口组件是否滚动到底部。是否有一个属性告诉滚动相对于溢出的父级在哪里?
谢谢!
【问题讨论】:
根据您的问题,我假设您正在使用给定链接中的组件。
如果是这样,我会像这样添加一个带有onScroll 侦听器的包装器div:
const Row = ({ index, style }) => (
<div className={index % 2 ? "ListItemOdd" : "ListItemEven"} style={style}>
Row {index}
</div>
);
class Example extends Component {
scrollCheck = event => {
const bottom = event.target.scrollHeight - event.target.scrollTop === event.target.clientHeight;
if (bottom) {
console.log("At The Bottom"); //Add in what you want here
}
};
render() {
return (
<Fragment>
<div onScroll={this.scrollCheck}>
<List
className="List"
height={150}
itemCount={1000}
itemSize={35}
ref={this.listRef}
width={300}
id="myDiv"
>
{Row}
</List>
</div>
</Fragment>
);
}
}
您的问题与here 非常相似,所以也可以检查一下。
【讨论】:
Element.scrollHeight:developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight