|
@@ -78,14 +78,19 @@ class WaterfallIndexScene extends scene {
|
|
|
let container = document.getElementById('advert-carousel');
|
|
|
container.innerHTML = swiperHTML;
|
|
|
// 创建swiper对象
|
|
|
- this.advertSwiper = new Swiper('.swiper-container-advert', {
|
|
|
- direction: 'horizontal',
|
|
|
- autoplay: true,
|
|
|
- pagination: {
|
|
|
- el: '.swiper-pagination-advert',
|
|
|
- bulletElement: 'li',
|
|
|
- },
|
|
|
- });
|
|
|
+ if (!this.advertSwiper) {
|
|
|
+ this.advertSwiper = new Swiper('.swiper-container-advert', {
|
|
|
+ direction: 'horizontal',
|
|
|
+ autoplay: true,
|
|
|
+ pagination: {
|
|
|
+ el: '.swiper-pagination-advert',
|
|
|
+ bulletElement: 'li',
|
|
|
+ },
|
|
|
+ });
|
|
|
+ // 更新swiper对象
|
|
|
+ } else {
|
|
|
+ this.advertSwiper.updateSlides();
|
|
|
+ }
|
|
|
this.moye.root.reRender();
|
|
|
}
|
|
|
|
|
@@ -204,6 +209,12 @@ class WaterfallIndexScene extends scene {
|
|
|
});
|
|
|
/* 将sliders插入到页面dom中 */
|
|
|
let swiperContainer = document.getElementById('waterfall-swiper');
|
|
|
+ /* 销毁除slide-0以外的全部slider, 防止页面元素重复 */
|
|
|
+ let sliderFirst = document.getElementById('slide-0');
|
|
|
+ if (swiperContainer && sliderFirst) {
|
|
|
+ swiperContainer.innerHTML = '';
|
|
|
+ swiperContainer.appendChild(sliderFirst);
|
|
|
+ }
|
|
|
sliders.forEach((slider, sliderIndex) => {
|
|
|
let slideDom = document.createElement('div');
|
|
|
slideDom.setAttribute('class', 'swiper-slide');
|
|
@@ -217,13 +228,18 @@ class WaterfallIndexScene extends scene {
|
|
|
swiperContainer.appendChild(slideDom);
|
|
|
});
|
|
|
/* 注册swiper */
|
|
|
- this.waterfallSwiper = new Swiper('.swiper-container-waterfall', {
|
|
|
- direction: 'vertical',
|
|
|
- pagination: {
|
|
|
- el: '.swiper-pagination-waterfall',
|
|
|
- bulletElement: 'li',
|
|
|
- },
|
|
|
- });
|
|
|
+ if (!this.waterfallSwiper) {
|
|
|
+ this.waterfallSwiper = new Swiper('.swiper-container-waterfall', {
|
|
|
+ direction: 'vertical',
|
|
|
+ pagination: {
|
|
|
+ el: '.swiper-pagination-waterfall',
|
|
|
+ bulletElement: 'li',
|
|
|
+ },
|
|
|
+ });
|
|
|
+ /* 更新swiper */
|
|
|
+ } else {
|
|
|
+ this.waterfallSwiper.updateSlides();
|
|
|
+ }
|
|
|
/* 重新渲染下,使新构造的swiper生效 */
|
|
|
this.moye.root.reRender();
|
|
|
}
|