vue中swiper的嵌套使用

本文想实现wap页面可以上下滑动,并且个别的轮播图可以有横向的自动轮播,下面将展示嵌套的两个轮播图

template页面

            <div class="commend-item">
              <div
                class="swiper-container"
                id="swiperIm1"
              >
                <div class="swiper-wrapper">
                  <div
                    class="swiper-slide"
                    v-for="(item,index) in commendList"
                    :key="index"
                  >
                    <div class="imgbox"><img
                        :src="item.normalColumnData.imagePath"
                        alt=""
                      ></div>
                  </div>
                </div>
              </div>
            </div>
            <div class="commend-item">
              <div
                class="swiper-container"
                dir="rtl"
                id="swiperIm2"
              >
                <div class="swiper-wrapper">
                  <div
                    class="swiper-slide"
                    v-for="(item,index) in commendList"
                    :key="`swiperIm2${index}` "
                  >
                    <div class="imgbox"><img
                        :src="item.normalColumnData.imagePath"
                        alt=""
                      ></div>
                  </div>
                </div>
              </div>
            </div>

第二个轮播加上 dir="rtl",可以反向轮播

script内容

   init(value) {
      let tempData = JSON.parse(JSON.stringify(value))
      const imageLength = tempData.length - 1
      //全局设置
      this.swiper1 = new Swiper('#swiper', {
        noSwipingClass: 'slide-auto',
        direction: 'vertical',
        observer: true,
        hashnav: true,
        hashnavWatchState: true,
        mousewheelControl: true,
        nextButton: ".page-next",
      })
      //第一个轮播页面
      this.swiper2 = new Swiper('#swiperIm1', {
        autoplay: 30,
        speed: 3000,
        autoplayDisableOnInteraction: false,
        observer: true,
        observeParents: true,
        loop: true,
        slidesPerView: 'auto',
        loopedSlides: imageLength,
      })
     //第二个轮播页面
      this.swiper3 = new Swiper('#swiperIm2', {
        autoplay: 30,
        speed: 3000,
        autoplayDisableOnInteraction: false,
        observer: true,
        observeParents: true,
        loop: true,
        slidesPerView: 'auto',
        loopedSlides: imageLength,
      })
    },

css页面(最重要!!!)

.swiper-container .swiper-wrapper {
  transition-timing-function: linear;
}

注意loop模式下不要使用free模式,否则会产生轮播异常,详见:

swiper官网

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值