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>
相关推荐
m0_6442226112 分钟前
HarmonyOS开发探索:自定义键盘-webview
前端·华为·计算机外设·移动开发·harmonyos·鸿蒙开发
铁匠匠匠24 分钟前
django学习入门系列之第三点《案例 小米商城二级菜单》
前端·css·经验分享·python·学习·django·前端框架
呀呀呀雅楠?25 分钟前
vue3(nuxt3)中使用ref获取不到子组件变量
前端·javascript·vue.js·nuxtjs
一颗苹果OMG34 分钟前
三栏布局,到底哪种最好用呢
前端·css
小秦学加瓦chen38 分钟前
使用docker创建nginx容器部署前端项目
前端·nginx·docker
小怪瘦791 小时前
Vue3使用PDFJS将后端查到的二进制数据转为图片
java·前端·javascript
m0_742887731 小时前
分享一个超级实用的东西——巴比达远程访问
前端·巴比达·免费内网穿透
前端张三2 小时前
vue2中vuedraggable设置部分元素不可拖拽,不可移动
前端·javascript·vue.js
一颗苹果OMG2 小时前
掌握this指向,让你在变量的拷贝中游刃有余
前端·javascript
墨轩尘2 小时前
axios之CancelToken取消请求
前端·javascript