我使用perfect-scroll插件
https://github.com/noraesae/perfect-scrollbar
当我使用ps-y-reach-end事件时

document.addEventListener('ps-y-reach-end', (event)=> {
console.log('Why this is printing multiple times when I reach Bottom, I wanted it to be single fire')
});问题是,当滚动条到达容器的底部时,事件会多次触发。
Web控制台打印:

请将y轴滚动到底部,您将多次看到控制台
发布于 2019-11-02 15:21:59
您需要使用布尔标志来处理此问题
var el = document.querySelector('.container');
Ps.initialize(el);
let loading = false
document.addEventListener('ps-y-reach-end', (event) => {
if (!loading) {
loading = true
alert('Why this is printing multiple times when I reach Bottom, I wanted it to be single fire')
}
});https://stackoverflow.com/questions/45612153
复制相似问题