【问题标题】:react-window how to know if its scrolled to bottomreact-window 如何知道它是否滚动到底部
【发布时间】:2019-05-10 12:34:09
【问题描述】:

我找不到如何知道here 中的一个窗口组件是否滚动到底部。是否有一个属性告诉滚动相对于溢出的父级在哪里?

谢谢!

【问题讨论】:

    标签: reactjs scroll


    【解决方案1】:

    根据您的问题,我假设您正在使用给定链接中的组件。
    如果是这样,我会像这样添加一个带有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 非常相似,所以也可以检查一下。

    【讨论】:

    猜你喜欢
    • 2017-06-26
    • 2015-03-06
    • 1970-01-01
    • 1970-01-01
    • 2014-07-11
    • 1970-01-01
    • 2011-07-05
    • 1970-01-01
    • 2019-01-17
    相关资源
    最近更新 更多