微信小程序swiper组件滑动卡死现象解决

项目中用swiper作为滑动展示展品页面,swiper-item高达49个

在使用过程中出现了滑动卡死的现象,解决方案如下

在swiper里面监听bindanimationfinish事件

bindanimationfinish在swiper卡死的时候也会触发(神奇)

<swiper bindanimationfinish="changeGoodsSwip" current="{{goodsIndex}}">

function:

changeGoodsSwip: function (detail) {
    if (detail.detail.source == "touch") {
        //当页面卡死的时候,current的值会变成0 
        if(detail.detail.current == 0){
            //有时候这算是正常情况,所以暂定连续出现3次就是卡了
            let swiperError = this.data.swiperError
            swiperError += 1
            this.setData({swiperError: swiperError })
            if (swiperError >= 3) { //在开关被触发3次以上
                console.error(this.data.swiperError)
                this.setData({ goodsIndex: this.data.preIndex });//,重置current为正确索引
                this.setData({swiperError: 0})
            }
        }else {//正常轮播时,记录正确页码索引
            this.setData({ preIndex: detail.detail.current });
            //将开关重置为0
            this.setData({swiperError: 0})
        }
    }
}

参考了愤怒的小鸟:https://blog.csdn.net/oagnuygnef/article/details/80506442

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值