vue关于swiper5.4.5的slide内滚动的解决方案

根据swiper作者给出的解决方案。代码如下`

this.mySwiper = new Swiper('.swiper-container', {
            direction: "vertical",
        })
        let that = this
        this.mySwiper.slides.on('touchstart', function (e) {
           
            that.startScroll = Math.ceil(this.scrollTop);
            that.touchStart = parseInt(e.targetTouches[0].pageY);
        }, true);
        this.mySwiper.slides.on('touchmove', function (e) {
           
            that.touchCurrent = parseInt(e.targetTouches[0].pageY);
            let touchesDiff = that.touchCurrent - that.touchStart;
            let slide = this;
            let onlyScrolling = ( slide.scrollHeight > slide.offsetHeight ) && //allow only when slide is scrollable
                    (
                        ( touchesDiff < 0 && that.startScroll === 0 ) || //start from top edge to scroll bottom
                        ( touchesDiff > 0 && that.startScroll === ( slide.scrollHeight - slide.offsetHeight ) ) || //start from bottom edge to scroll top
                        ( that.startScroll > 0 && that.startScroll < ( slide.scrollHeight - slide.offsetHeight ) ) //start from the middle
                    );
                    console.log(  
                        ( touchesDiff < 0 && that.startScroll === 0 ) ,
                        ( touchesDiff > 0 && that.startScroll === ( slide.scrollHeight - slide.offsetHeight ) ) , //start from bottom edge to scroll top
                        ( that.startScroll > 0 && that.startScroll < ( slide.scrollHeight - slide.offsetHeight ) ),//start from the middle
                        that.startScroll,slide.scrollHeight - slide.offsetHeight 
                     )
            if (onlyScrolling) {
                e.stopPropagation();
            }
        }, true);    


你可能感兴趣的:(vue.js,javascript)