-1

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

4

1 回答 1

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

于 2020-06-02T07:53:26.153 回答