TA的每日心情 | 开心 2020-9-22 16:12 |
---|
签到天数: 1 天 [LV.1]初来乍到
新手上路
- 积分
- 13
|
参考方案:
//外面大的 swiper初始化
const mySwiper = new Swiper ('#pageSwiper', {
width: window.innerWidth,
height: window.innerHeight,
initialSlide,
direction : 'vertical',
effect : 'coverflow',
lazy: {
loadPrevNext: true,
loadOnTransitionStart: true,
},
noSwiping : true,
noSwipingClass : 'stop-swiping',
on: {
init: function(){
swiperAnimateCache(this); //隐藏动画元素
swiperAnimate(this); //初始化完成开始动画
},
slideChange: function(){
if(this.activeIndex === 1) {
swiperAnimate(gallerySwiper); // 重点部分,这样嵌入的就可以初始化 完美展示动画了
} else {
swiperAnimate(this);
}
},
}
});
// 第二页嵌入的 swiper
const gallerySwiper = new Swiper ('#gallerySwiper', {
initialSlide: 0,
loop : true,
effect : 'fade',
lazy: {
loadPrevNext: true,
loadOnTransitionStart: true,
},
nested:true,
on:{
slideChange: function(){
//每个slide切换结束时也运行当前slide动画
swiperAnimate(this);
},
},
pagination: {
el: '.gallery-pagination',
type : 'custom',
renderCustom: function (swiper, current, total) {
const html = `<div class="swiper-dots">
<span class="swiper-dot ${current === 1 && 'active'}"></span>
<span class="swiper-dot ${current === 2 && 'active'}"></span>
</div>`;
return html;
}
}
}); |
|