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>
相关推荐
用户47949283569157 分钟前
我只是给Typescript提个 typo PR,为什么还要签协议?
前端·后端·开源
程序员爱钓鱼29 分钟前
Next.js SSR 项目生产部署全攻略
前端·next.js·trae
程序员爱钓鱼30 分钟前
使用Git 实现Hugo热更新部署方案(零停机、自动上线)
前端·next.js·trae
颜颜yan_1 小时前
DevUI + Vue 3 入门实战教程:从零构建AI对话应用
前端·vue.js·人工智能
国服第二切图仔2 小时前
DevUI Design中后台产品开源前端解决方案之Carousel 走马灯组件使用指南
前端·开源
无限大62 小时前
为什么浏览器能看懂网页代码?——从HTML到渲染引擎的奇幻之旅
前端
福尔摩斯张2 小时前
Linux信号捕捉特性详解:从基础到高级实践(超详细)
linux·运维·服务器·c语言·前端·驱动开发·microsoft
2401_860319522 小时前
DevUI组件库实战:从入门到企业级应用的深度探索 ,如何快速安装DevUI
前端·前端框架
cc蒲公英2 小时前
javascript有哪些内置对象
java·前端·javascript
zhangwenwu的前端小站3 小时前
vue 对接 Dify 官方 SSE 流式响应
前端·javascript·vue.js