我正在使用完美滚动插件
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')
});
问题是当滚动到达容器底部时,事件会多次触发。
请将y轴滚动到底部,您将多次看到控制台
答案 0 :(得分:0)
您需要使用布尔标志来处理此问题
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')
}
});