html轮播图小屏不居中显示,[解决]小程序轮播图不同手机屏幕适配展示

1.image绑定bindLoad方法

2.swiper绑定_bindChange方法

indicator-active-color="{{ itemStyle.btnColor }}" bindchange="_bindChange" data-item-key="{{ itemIndex }}" style="height: {{imgHeightsThis}}px !important">

data: {

imgHeights: [], // 图片的高度

imgCurrent: 0, // 当前banne所在滑块指针

imgHeightsThis:0

},

methods: {

/**

* 计算图片高度

*/

_imagesHeight: function(e) {

let winWid = wx.getSystemInfoSync().windowWidth; //获取当前屏幕的宽度

let imgh = e.detail.height;//图片高度

let imgw = e.detail.width;//图片宽度

let swiperH = (winWid * imgh)/imgw;//等比设置swiper的高度。 即 屏幕宽度 / swiper高度 = 图片宽度 / 图片高度 -> swiper高度 = (屏幕宽度 * 图片高度) / 图片宽度

let imgHeights = this.data.imgHeights;

// 把每一张图片的高度记录到数组里

imgHeights.push(swiperH);

this.setData({

imgHeights,

imgHeightsThis:imgHeights[0]

});

},

/**

* 记录当前指针

*/

_bindChange: function(e) {

this.setData({

imgCurrent: e.detail.current,

imgHeightsThis:this.data.imgHeights[e.detail.current]

});

},

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值