swiper获取切换-swiper分页不显示-swiper同步获取当前切换的是第几个或索引-swiper特殊场景-swiper销毁

// this.activeIndex 切换到当前的索引值
new Swiper('.swiper', {
            loop: data.length > 1 ? true : false,
            pagination: { // 分页配置函数
                el: '.swiper-pagination',
            },
            autoplay: {  // 自动切换配置函数
                delay: 3000,
                stopOnLastSlide: false,
                disableOnInteraction: true,
            },
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
            },
			on:{
			   // 以下函数的逻辑获取第几张是在循环模式下,loop:true,非循环模式下第几张直接是 this.activeIndex+1(索引+1)
                slideChangeTransitionStart: function () { // 切换动作开始函数
                    let ind = 1; // 同按钮同步当前切换是第几个变量
                    // star 
                    // data 图片数组
                    if(this.activeIndex == 0){
                        ind = data.length;
                    } else if(this.activeIndex == data.length+1){
                        ind = 1;
                    } else {
                        ind = this.activeIndex;
                    }  
                    // end 
                    $('#img-ind').text(ind); // 最终获取到的同步值输出到页面
                }
            },
             slideChangeTransitionEnd: function () { // 切换动作结束函数
             
             },
             slideChange: function () { // swiper切换了干某些事的函数
             	// do somethings
             },
  })
swiper 不停销毁重建场景

重建之前最好先销毁

var swiper = null;
swiper && swiper.destroy  && swiper.destroy(false, true)
swiper = new Swiper('.swiper')

以上个别方法支持版本>=4.0.0

小于4.0.0,兼容IE10写法:

	new Swiper('.swiper', {
     	loop: data.length > 1 ? true : false,
       	pagination: '.swiper-pagination',
      	nextButton: '.swiper-button-next',
       	prevButton: '.swiper-button-prev',
      	onTransitionStart: function (ele) {
           let ind = 1;
           if(ele.activeIndex == 0){
               ind = data.length;
           } else if(ele.activeIndex == data.length+1){
               ind = 1;
           } else {
               ind = ele.activeIndex;
           }  
           $('#img-ind').text(ind);
       },
      onTransitionEnd: function (ele) { // 切换动作结束函数
       },
      onChange: function (ele) { // swiper切换了干某些事的函数
       	// do somethings
       },
   })
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值