欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

swiper点击出现空白的解决办法

程序员文章站 2024-02-21 17:18:22
...

swiper点击出现空白的解决办法

<div class="swiper-container2 ">
    <div class="swiper-wrapper">
        <div class="swiper-slide swiper-slide-active">全部</div>
        <div class="swiper-slide">电商类</div>
        <div class="swiper-slide">金融类</div>
        <div class="swiper-slide">医疗类</div>
        <div class="swiper-slide">地产类</div>
        <div class="swiper-slide">Slide 6</div>
        <div class="swiper-slide">Slide 7</div>
        <div class="swiper-slide">Slide 8</div>
        <div class="swiper-slide">Slide 9</div>
        <div class="swiper-slide">Slide 10</div>
    </div>
</div>

var mySwiper2 = new Swiper('.swiper-container2', {
      slidesPerView: 5,
      spaceBetween: 30,
      centeredSlides: true,
      loop: true,
      on: {
          click: function() {
              console.log(this.clickedIndex)
              mySwiper2.slideTo(this.clickedIndex);
              mySwiper2.slideToLoop(this.realIndex);//解决swiper空白
              mySwiper6.slideTo(this.clickedIndex);
              mySwiper6.slideToLoop(this.realIndex);
          },
          touchMove: function() {
              mySwiper2.lockSwipes(); //禁止滑动
          },
      },
  });