关于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>
	swiper image {
		width:100%;
	}
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是为了保证让点能够显示到图片上;默认高度还是有点高,所以减掉一点
    })

  },

使用前
未正常显示图片
使用后
使用后正常显示图片高度

<swiper-item>
				<view class="swiper-item">
					<view class="addCar" @tap="toAddCar">
						<image mode="widthFix" src="http://etc-app.oss-cn-beijing.aliyuncs.com/image_201905211345266507.png"></image>
						<view class="one">添加车辆查违章</view>
						<view class="two">享受新违章通知、在线办理违章等服务</view>
					</view>
				</view>
			</swiper-item>

swiper-item下面如果有一个大的view包裹住所有;也可以撑起来;swiper;这里仅仅是让撑起来;当然也可以直接给swiper设置高度;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值