导航

萌即是正义!时不时分享一些ACG活动记录与有趣代码的小站!

侧边栏
最新评论
广树管理员
2025-02-19 22:04
@老张博客:大佬呀,这第几次问这个问题了呀
老张博客
2025-02-19 21:18
我在想博主是不是一位女生呀
广树管理员
2025-02-19 20:46
@菲兹克斯喵:是呀,学生时代最喜欢的小说
菲兹克斯喵
2025-02-19 20:04
前段时间刚看完文学少女第九卷,后面没什么时间了 确实好看,快 20 年的小说了
广树管理员
2025-02-19 08:23
@某科学的贝壳:哈哈哈,确实属于有生之年了
正在攻略

logo_kai.jpg


PSN奖杯卡

PSN奖杯卡

赞助商广告

让Swiper移动端超出一屏的部分滚动显示而不是触发滑到下一页

作者:广树时间:2017-12-25 10:08:46分类:JavaScript

swiper版本为3.4.2。

因为效果需要,如果页面内容超过屏幕高度则先触发overflow的滚动条,当滚动条滚动到底部再触发swiper的页面滑动效果。

    var swiper = new Swiper('.swiper-container', {
        direction: 'vertical',
    });
    var startScroll, touchStart, touchCurrent;
    swiper.slides.on('touchstart', function (e) {
        startScroll = this.scrollTop;
        touchStart = e.targetTouches[0].pageY;
    }, true);
    swiper.slides.on('touchmove', function (e) {
        touchCurrent = e.targetTouches[0].pageY;
        var touchesDiff = touchCurrent - touchStart;
        var slide = this;
        var onlyScrolling =
                ( slide.scrollHeight > slide.offsetHeight ) && 
                (
                    ( touchesDiff < 0 && startScroll === 0 ) || 
                    ( touchesDiff > 0 && startScroll === ( slide.scrollHeight - slide.offsetHeight ) ) || 
                    ( startScroll > 0 && startScroll < ( slide.scrollHeight - slide.offsetHeight ) ) 
                );
        if (onlyScrolling) {
            e.stopPropagation();
        }
    }, true);

donate.png

1210 x 50(蓝底).png

cloudcone