关于swiper的轮播图,默认直接放图片,无法让图片展示默认的高度,从而撑起理想的的swiper;
<swiper circular='true' indicator-dots="1" autoplay="true" style='height:{{bannerHeight-10}}px'>
<block wx:for="{{imageList}}">
<swiper-item>
<image src='{{item.image}}' bindload='imageLoad' mode="widthFix" data-path="{{item.path}}" bindtap='to' />
</swiper-item>
</block>
</swiper>
data:{
bannerHeight:0 //先来个默认值
}
imageLoad:function (e) { // 注意这里是在图片的bindload使用的
var res = wx.getSystemInfoSync();
var imgwidth = e.detail.width;
var imgheight = e.detail.height;
var ratio = imgwidth / imgheight;
this.setData({
bannerHeight: res.windowWidth / ratio // 用的时候-10是为了保证让点能够显示到图片上;默认高度还是有点高,所以减掉一点
})
},
使用前
使用后