首页 > 我用iScroll5去实现下拉刷新效果,多次触发问题

我用iScroll5去实现下拉刷新效果,多次触发问题

我用iScroll5去实现下拉刷新效果,但是我鼠标向下拉的时候触发了,但是我不松开,又下拉一下就又会触发,求教啊
我的代码是下边写的,写的很烂,希望大家帮我看看,都哪里需要改,改了好久都不行

function loaded() {
        myScroll = new IScroll('#wrapper', {mouseWheel: true, probeType: 1});
        myScroll.on('scroll', updatePosition);
        var mouseY = 0;
        var moveY = 0;
        function updatePosition() {

            var getWrapper = document.getElementById('wrapper');
            var getWrapperHeight = -(-document.getElementById('wrapper').scrollHeight + document.getElementById('wrapper').clientHeight + 32);
            //监听鼠标按下事件
            getWrapper.addEventListener('mousedown',getStartPage);

            function getStartPage(e){
                var e = e || window.event;
                mouseY = e.pageY;
                return mouseY;
            }
            console.log(mouseY);
            
            getWrapper.addEventListener('mousemove',getmovePage);
            
            //监听鼠标移动事件
            function getmovePage(e){
                var e = e || window.event;
                moveY = e.pageY;
                return moveY;
            }
            console.log(moveY);

            //先判断是向上拉动还是向下拉动
            if (this.y + getWrapperHeight < -2) {
            //再判断移动的距离
                if(mouseY-moveY>30){
                    console.log("向上拉动")
                }

            }
            //先判断是向上拉动还是向下拉动 
            if (this.y > 20) {
            //再判断移动的距离
                if(mouseY-moveY<-30){
                    console.log("向下拉动")
                }
            }
        }

        document.addEventListener('touchmove', function (e) {
            e.preventDefault();
        }, false);
    }

1:为什么我拉动的前两下打印出来的mouseY和moveY为什么都为0,怎么解决呢
2:我鼠标不抬起,只是滑动一段之后停顿一下再划一下,就会出现2个或者更多个打印的“向下拉动”
求大神帮帮忙,弄了半天还没弄好


https://github.com/ximan/dropload。可以试试这个,我觉得iScroll有点笨重而且性能也不是稳定。

【热门文章】
【热门文章】