2016-10-27 135 views
0

我有一張幻燈片,但我的幻燈片重複三個項目!如何停止重複幻燈片?如果有1張幻燈片放映,如果是兩張幻燈片放映兩張,如果是10張幻燈片放映10:|這是我的配置Swiper旋轉木馬幻燈片PerView無法正常工作

var swiper = new Swiper('.slides-per-view', { 
    pagination: '.swiper-pagination', 
    speed: 800, 
    loop: true, 
    slidesPerView: 3, 
    centeredSlides: true, 
    spaceBetween: 30, 
    grabCursor: true, 
    paginationClickable: '.swiper-pagination', 
    nextButton: '.swiper-button-next', 
    prevButton: '.swiper-button-prev' 
}); 

,這是我的HTML代碼

<div class="swiper-container slides-per-view" dir="rtl"> 
    <div class="swiper-wrapper"> 
     <div class="swiper-slide"> 
      <figure> 
       <a href="#"><img draggable="false" src="assets/pictures/activities/1.jpg" class="img-responsive" alt=""></a> 
       <figcaption class="text-light text-center"> Title</figcaption> 
       <div class="more text-center margin-bottom-30"> 
        <p class="text-blue"><i class="fa fa-calendar"></i> Date</p> 
        <a href="" class="btn btn-info-border text-dark transition-5"> Read More </a> 
       </div> 
      </figure> 
     </div> 
    </div> 
    <div class="swiper-pagination"></div> 
    <div class="swiper-button-prev"></div> 
    <div class="swiper-button-next"></div> 
</div> 

看這個圖片,請 enter image description here

+0

您是否嘗試將此變量(slidesPerView:3)更改爲1? – Zorken17

+0

@ Zorken12我需要展示3個項目,但當我的幻燈片是3!不是何時滑動 –

+0

我在代碼中看不到問題。如果您只有一個圖塊,滑塊將只顯示1個項目。看看這個:https://jsfiddle.net/thozpvj7/ – Zorken17

回答

2

你不能有循環設置爲true,slidesPerView 3,如果你只有一個瓷磚。所以這是你可以做的:

var isLoop = true; 

if($('.swiper-slide')).length < 3) { 
    isLoop = false; 
} 

var swiper = new Swiper('.swiper-container', { 
    pagination: '.swiper-pagination', 
    speed: 800, 
    loop: isLoop, //<--- set if loop is true or not 
    slidesPerView: 3, 
    centeredSlides: true, 
    spaceBetween: 30, 
    grabCursor: true, 
    paginationClickable: '.swiper-pagination', 
    nextButton: '.swiper-button-next', 
    prevButton: '.swiper-button-prev' 
}); 
+0

是的,謝謝你的問題是循環, –

+0

不客氣。請喜歡我的答案,並將它標記爲一個,如果它回答你的問題。 – Zorken17

+0

原諒我的大膽編輯,對不起 –

相關問題