6

我正在使用完美滚动插件

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')
 });

问题是当滚动到达容器底部时,事件会触发不止一次。

JSFiddle 演示

Web 控制台打印: 在此处输入图像描述

请将y轴滚动到底部,您将多次看到控制台

4

1 回答 1

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')
    }

});
于 2019-11-02T07:21:59.010 回答