微信小程序swiper自适应高度
swiper组件如果没有高度是不显示的,网上有的朋友会用js去动态获取图片高度再给swiper设置高度(这种方法繁琐)我下面用css来让swiper自适应(bannerList为存放图片的数组,backgroundImg为图片地址):1.在外侧给个容器,设置position为relative2.取出第一个图片,设置宽度100%,mode为widthFix(高度自适应)3.给swip...
·
swiper组件如果没有高度是不显示的,网上有的朋友会用js去动态获取图片高度再给swiper设置高度(这种方法繁琐)
我下面用css来让swiper自适应(bannerList为存放图片的数组,backgroundImg为图片地址):
1.在外侧给个容器,设置position为relative
2.取出第一个图片,设置宽度100%,mode为widthFix(高度自适应)
3.给swiper设置绝对定位,高度宽度都100%,就可以实现swiper高度自适应
<view style="position:relative">
<image style="opacity:0;width:100%" src="{{bannerlist[0].backgroundImg}}" mode="widthFix"></image>
<swiper style="height:100%;position:absolute;left:0;top:0;z-index:3;width:100%" class="swiper" indicator-dots="true" indicator-color="#ccc" indicator-active-color="#fff" autoplay="false">
<swiper-item wx:for="{{bannerlist}}" wx:key="index"><image src="{{item.backgroundImg}}" mode="widthFix"></image></swiper-item>
</swiper>
</view>
更多推荐



所有评论(0)