一.移動端-需求swiper 4.0.3實現層疊輪播javascript
二.實現效果以下java
三.方案:查找了下發現使用swiper的切換效果coverflowEffect能夠實現ide
1.coverflow是相似於蘋果將多首歌曲的封面以3D界面的形式顯示出來的方式oop
2.coverflow的屬性:this
rotate:slide作3d旋轉時Y軸的旋轉角度。默認50。
stretch:每一個slide之間的拉伸值,越大slide靠得越緊。 默認0。
depth:slide的位置深度。值越大z軸距離越遠,看起來越小。 默認100。
modifier:depth和rotate和stretch的倍率,至關於depth*modifier、rotate*modifier、stretch*modifier,值越大這三個參數的效果越明顯。默認1。
slideShadows:開啓slide陰影。默認 true。3d
四.代碼:blog
this.swiper = new Swiper('.case-swiper-container', { centeredSlides: false, // 選中slide居中顯示 initialSlide: 1, // 默認選中項索引 slidesPerView: 1, // 自動匹配每次顯示的slide個數,loop='auto'模式下,還須要設置loopedSlides effect: 'coverflow', // 切換效果-3d coverflowEffect: { rotate: 0, stretch: 10, depth: 160, modifier: 2, slideShadows: true }, pagination: { el: '.swiper-pagination' }, on: { init() { const item = JSON.parse($($(this.$el[0]).find('.swiper-slide')[this.activeIndex]).attr('data-item')); _this.updateCaseInfo(item); }, slideChange() { // 輪播slide同時更新文字描述 const item = JSON.parse($($(this.$el[0]).find('.swiper-slide')[this.activeIndex]).attr('data-item')); _this.updateCaseInfo(item); } } });
5.注意:索引
5.1若指望選中slide居中顯示,則設置centerSlides:true,若指望在默認顯示輪播時去掉左邊空白,可設置initialSlide:1ip
5.2不要試圖控制默認選中項的寬高,會影響正常的輪播效果,只能經過調整coverflow的相關屬性和swiper容器的寬高達到最終的效果swiper