Swiper 在 vertical 模式下 autoHeight 失效的問題,導致頁面出現多余的空白高度,網上找了很多方法都無效,我直接暴力更改。
<SwiperclassName='index-swiper'direction={'vertical'}mousewheel={true}centeredSlides={true}autoHeight={true}slidesPerView="auto" // 這里 autoobserveParents={true}observer={true}modules={[Mousewheel]}onSlideChange={(swiper) => {if(swiper.activeIndex == 5) { // 我的item有6條,取最后有問題的一條const dom = document.getElementsByClassName('swiper-wrapper')[0]; // 獲取到 transform 的元素const y = (swiper.height - (swiper as any).slidesSizesGrid[swiper.activeIndex]) / 2 + 'px'; // 具體 translate 數值根據計算出來的結果而定。(dom as any).style.transform += `translateY(${y})` // 暴力更改}}}
><SwiperSlide><Video></Video></SwiperSlide><SwiperSlide><ModelDisplay></ModelDisplay></SwiperSlide><SwiperSlide><Introduction></Introduction></SwiperSlide><SwiperSlide><Appointment></Appointment></SwiperSlide><SwiperSlide><ServiceSupport></ServiceSupport></SwiperSlide><SwiperSlide><Footer></Footer></SwiperSlide>
</Swiper>