2014-04-17 44 views
0

我想用這個可怕的JS滑塊(Swiper)使用其完整的API來實現特定的行爲,但我一直運氣不振,直到現在......需要一些幫助:Swiper滑塊。預先製作一張幻燈片並模擬過渡到它

現狀:

  • 只有一張幻燈片在開始。

我想什麼,每次我點擊一個按鈕是:

  • 動態創建之前在每種情況下的第一個新的幻燈片 - >容易的事情,與前置() Swiper API的方法:)
  • 但是(這裏是問題)我希望最終用戶只是加載前一張幻燈片的感覺,即點擊按鈕並看到向左滑動過渡...

我想要這種「稀有」行爲,因爲我的滑塊必須顯示數百張幻燈片,並且從一開始就一次加載所有幻燈片,導致頁面加載速度非常緩慢,因爲它必須下載數百個圖像...

在此先感謝。

回答

2

我終於得到了它的工作,像這樣:

一旦按鈕(帶class = 「上一頁」)點擊:

$(document).on('click', '.prev', function() { 

    // If it is the first slide... 
    if (mySwiper.activeIndex == 0) { 

     // Slide content 
     var slide = '<p>New slide</p>'; 

     // Creation of the slide (it instantly moves to index 0 --> the new slide) 
     mySwiper.prependSlide(slide); 

     // And then instant (speed = 0) swipe to slide with index 1 
     // (the one we were watching before creating the new...) 
     mySwiper.swipeTo(1, 0, false); 

     // Finally, we implement the visual transition to new slide (index 0) 
     mySwiper.swipePrev(); 
    } 
}); 

我希望它可以幫助別人。 謝謝。

相關問題