function DataInfo() {
const [dom, setDom] = useState(HTMLDivElement | null);
const [logData, setLogData] = useState('');
// 獲取數據的方法
function getLogPages () {
...
}
// 監聽頁面滾動
const handleOnScroll = () => {
if (dom) {
const contentScrollTop = dom.scrollTop; //滾動條距離頂部
const clientHeight = dom.clientHeight; //可視區域
const scrollHeight = dom.scrollHeight; //滾動條內容的總高度
if (contentScrollTop + clientHeight >= scrollHeight) {
getLogPages(); // 獲取數據的方法
}
}
};
return (
<div className="modal-body logHeight"
style={{ height: '480px' }}
ref={(dom) => {
setDom(dom);
}}
onScrollCapture={() => handleOnScroll()}
>
{logData}
</div>
)
}