SnowGuest

SnowGuest

这里是 SnowGuest的博客站点,只会记录一些有意思的日常事
bilibili
github

WeChat Mini Program Swiper Adaptive Height Pitfall Record

Today, when writing a WeChat mini program, I encountered an issue where the content inside the Swiper was not displaying on the actual device, although it appeared normal in the developer environment.

The specific code is:

<Page>
<View></View> // height:120rpx
  <Swiper> // flex:1
    <Swiper-item>
    </Swiper-item>
    <Swiper-item></Swiper-item>
  </Swiper>
</Page>

In this situation, using flex works fine in the developer tool, but in actual device debugging, preview, and experience version, the Swiper height successfully fills the screen, but the Swiper-item height is 0, resulting in no content being displayed.

The solution here is quite straightforward:

.className-swiper{
  height:calc(100vh - calc(120rpx - env(safe-area-inset-bottom)));
}

Manually calculate the height, and it is recommended to fix the height of other additional Views. Avoid using flex1 at the same time as it will override the height.

end

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.