js使⽤swiper实现层叠轮播
⼀.移动端-需求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
rotate属性},
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容器的宽⾼达到最终的效果
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论