欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 资讯 > react 中 Swiper vertical 模式下 autoHeight 失效的问题

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

2025/9/5 2:31:06 来源:https://blog.csdn.net/weixin_41645458/article/details/139981112  浏览:    关键词:react 中 Swiper vertical 模式下 autoHeight 失效的问题

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>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词