【问题标题】:scroll to first element using List and AutoSizer doesn't work使用 List 滚动到第一个元素,AutoSizer 不起作用
【发布时间】:2020-11-03 12:13:16
【问题描述】:

当用户单击分页按钮时,我想向上滚动到列表中的第一个元素。 到目前为止,我遇到了 scrollToRow 和 scrollToIndex ,它们都没有工作。

这是我当前的代码:

<AutoSizer disableWidth>
{({ height }) => (
    <div>
        <List
            ref="list"
            height={height}
            rowCount={this.state.items.length}
            rowHeight={115}
            rowRenderer={this._rowRenderer}
            width={1}
            scrollToRow={0}
            containerStyle={{
                width: '100%',
                maxWidth: '100%',
            }}
            style={{
                width: '100%',
                marginBottom: '10px',
            }}
        />
    </div>
)}
</AutoSizer>

【问题讨论】:

    标签: reactjs react-virtualized


    【解决方案1】:

    经过一番思考,我发现没有必要再使用 react-virtualized 包了。因为我重构了列表以使用 SSR 分页一次显示 24 个项目。所以,这有点矫枉过正。

    无论如何,我只是重用了相同的 _rowRenderer() 函数将项目映射到列表中。为了实现滚动行为,我刚刚添加了“溢出:滚动”的样式属性。 就是这样。

    【讨论】:

      猜你喜欢
      • 2018-10-31
      • 1970-01-01
      • 2021-02-05
      • 1970-01-01
      • 2015-06-16
      • 2011-10-04
      相关资源
      最近更新 更多