react 中 Swiper vertical 模式下 autoHeight 失效的问题

Swiper 在 vertical 模式下 autoHeight 失效的问题,导致页面出现多余的空白高度,网上找了很多方法都无效,我直接暴力更改。

javascript 复制代码
<Swiper
  className='index-swiper'
  direction={'vertical'}
  mousewheel={true}
  centeredSlides={true}
  autoHeight={true}
  slidesPerView="auto" // 这里 auto
  observeParents={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>
相关推荐
再吃一根胡萝卜35 分钟前
DSH 插件的 Host 与 Client:为什么「只加载了 Host」,以及要不要自己写 Client 加载器
前端
parade岁月1 小时前
AI 写的前端代码为什么总像 5 年前的?Chrome 官方出手了
前端
tryCbest1 小时前
Vue系列——第 15 篇:内置组件全家桶——Transition、Teleport、Suspense、KeepAlive
前端·vue.js
易师傅2 小时前
技术面试已死?AI 时代,真正拉开程序员差距的是什么?
前端·后端·程序员
jay神2 小时前
基于深度学习的交通流量预测系统(Web 版)
前端·人工智能·深度学习·yolo·计算机毕业设计
AiMan2 小时前
别再把秘塔会话逐个点开:这可把秘塔多个会话一次导出?AI导出鸭
前端·后端·面试
AiMan2 小时前
你好,请问可以一键导出Dola多个对话框内容吗?一键导出一整年哦
前端
Moment3 小时前
写给迷茫的应届生,怎样在 AI 时代争取更多机会
前端·后端·面试
fengci.3 小时前
CTF2MISC中等部分
开发语言·前端·学习
涛涛ing3 小时前
那个PR太干净了,干净到我差点直接点了合并
前端