滑动连续循环,在滑动

时间:2017-05-05 09:48:50

标签: swiper

我正在使用swiper的这种配置:

var swiper = new Swiper('.swiper-container', { spaceBetween: 30, slidesPerView: 3, speed: 2500, centeredSlides: true, autoplay: 1000, autoplayDisableOnInteraction: false, loop: true });

到目前为止,此工作正常。但是,滑动器是否可以在每个3个滑块之间停止?现在总有一个休息时间,直到接下来的3个幻灯片滑入。我正在寻找一个无限循环滑块选项。这可能吗?

3 个答案:

答案 0 :(得分:1)

是的,有可能,大mariorendic

var swiperOptions = {
  loop: true,
  freeMode: true,
  spaceBetween: 0,
  grabCursor: true,
  slidesPerView: 7,
  loop: true,
  autoplay: {
    delay: 1,
    disableOnInteraction: true
  },
  freeMode: true,
  speed: 5000,
  freeModeMomentum: false
};

var swiper = new Swiper(".swiper-container", swiperOptions);
body {
  margin: 0;
  padding: 0;
  background: #eee;
  font-family: sans-serif;
  font-size: 14px;
  background: #404449;
  
}

.swiper-container {
  height: calc(100vh - 120px);
  margin: 60px;
}


.swiper-slide {
  width: 28vw;
  overflow: hidden;
  background-position: top;
  background-size: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
  font-weight: bold;
}

.swiper-wrapper {
  -webkit-transition-timing-function:linear!important; 
  -o-transition-timing-function:linear!important;
  transition-timing-function:linear!important; 
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.0.7/js/swiper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.0.7/css/swiper.min.css" rel="stylesheet"/>
<div class="swiper-container">
  <div class="swiper-wrapper">
    <div class="swiper-slide" style="background-image: url(https://placekeanu.com/250/g);">1</div>
     <div class="swiper-slide" style="background-image: url(https://placekeanu.com/260);">2</div>
     <div class="swiper-slide" style="background-image: url(https://placekeanu.com/270);">3</div>
     <div class="swiper-slide" style="background-image: url(https://placekeanu.com/270/y);">4</div>
     <div class="swiper-slide" style="background-image: url(https://placekeanu.com/280/y);">5</div>
    <div class="swiper-slide" style="background-image: url(https://placekeanu.com/190/y);">6</div>
    <div class="swiper-slide" style="background-image: url(https://placekeanu.com/300/);">7</div>
  </div>
</div>

https://codepen.io/tristanisginger/pen/dypxRbv

答案 1 :(得分:0)

目前没有可配置的方式设置autoplay: 0,因为条件测试不区分布尔值false和“假”值0

https://github.com/nolimits4web/Swiper/blob/21d2a1da5b9b2e9610ec4005aad337a4af4d729f/src/js/core.js#L590。 (另请参阅第621行)

答案 2 :(得分:0)

我遇到了类似的问题,原因是每次调用build方法时,swiper的页面都会不断添加新元素(在我的情况下为widget)。解决方法是在添加元素之前清除所有页面或项目列表,以确保您摆脱了上一个版本中的所有先前元素。