你好,我想要检查用户是否滚动到了页面底部。
我正在使用以下函数进行检查:
const handleScroll = (event) => {
const bottom = event.target.scrollHeight - event.target.scrollTop === event.target.clientHeight;
if(bottom){
console.log('hello');
}
}
但问题是我的应用程序看起来像这样: 目前,函数仅在内部滚动条位于底部时才起作用。但是我希望它在外部滚动条到达底部时触发。
整个代码如下:
const handleScroll = (event) => {
const bottom = event.target.scrollHeight - event.target.scrollTop === event.target.clientHeight;
if(bottom){
console.log('hello');
}
}
return (
<div className='main' onScroll = {handleScroll}>
<div className='project-counter'>{filteredProjects.length > 0 ? (<p>Gevonden projecten : {filteredProjects.length}</p>) : null}</div>
{pro.map(project => (
<div className='view-container' key={project._id}>
<div className='hours-container'>
<table>
<tr>
<th className='tb-first'>Datum</th>
<th className='tb-first'>medewerker</th>
<th>Dienst</th>
<th>Toelichting</th>
<th>Aantal</th>
</tr>
{project.projectHours.map(hour => (
<tr>
<td>{hour.created_at}</td>
<td>{hour.employee.name}</td>
<td>{hour.type.label}</td>
<td>{hour.note}</td>
<td>{hour.hours.toFixed(2)}</td>
</tr>
))}
</table>
</div>
</div>
))}
</div>
)