【问题标题】:How to detect the end of the list element on scroll event?如何在滚动事件中检测列表元素的结尾?
【发布时间】:2020-06-02 07:45:34
【问题描述】:

如何在滚动事件中检测列表元素的结束?假设我有数组[1,2,3,4,5,6,7,8,9,10],我需要检测滚动是否到达列表的末尾并返回值(在这种情况下值为10)?这是我的 sn-p 代码:https://codesandbox.io/s/react-window-detect-last-element-on-scrolling-down-oo99p

【问题讨论】:

    标签: reactjs react-window


    【解决方案1】:

    您可以对父 div 使用 onScroll 事件:

    const onScroll = (event) => {
      var element = event.target;
      if (element.scrollHeight - element.scrollTop === element.clientHeight)
      {
          console.log(dataArray[dataArray.length - 1]);
      }
    } 
    

    在操场上查看:https://codesandbox.io/s/react-window-detect-last-element-on-scrolling-down-c4sv0?file=/src/index.js

    【讨论】:

      猜你喜欢
      • 2015-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-15
      • 1970-01-01
      • 1970-01-01
      • 2023-01-30
      相关资源
      最近更新 更多