一.移动端-需求swiper 4.0.3实现层叠轮播

二.实现效果如下

三.方案:查找了下发现使用swiper的切换效果coverflowEffect可以实现

  1.coverflow是类似于苹果将多首歌曲的封面以3D界面的形式显示出来的方式

  2.coverflow的属性:

    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。

四.代码:

 

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:1

  5.2不要试图控制默认选中项的宽高,会影响正常的轮播效果,只能通过调整coverflow的相关属性和swiper容器的宽高达到最终的效果