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>
相关推荐
江号软件分享28 分钟前
有效保障隐私,如何安全地擦除电脑上的敏感数据
前端
web守墓人1 小时前
【前端】ikun-markdown: 纯js实现markdown到富文本html的转换库
前端·javascript·html
Savior`L2 小时前
CSS知识复习5
前端·css
许白掰2 小时前
Linux入门篇学习——Linux 工具之 make 工具和 makefile 文件
linux·运维·服务器·前端·学习·编辑器
中微子6 小时前
🔥 React Context 面试必考!从源码到实战的完整攻略 | 99%的人都不知道的性能陷阱
前端·react.js
中微子7 小时前
React 状态管理 源码深度解析
前端·react.js
加减法原则8 小时前
Vue3 组合式函数:让你的代码复用如丝般顺滑
前端·vue.js
yanlele9 小时前
我用爬虫抓取了 25 年 6 月掘金热门面试文章
前端·javascript·面试
lichenyang4539 小时前
React移动端开发项目优化
前端·react.js·前端框架
天若有情6739 小时前
React、Vue、Angular的性能优化与源码解析概述
vue.js·react.js·angular.js