在mypage.js文件中动态获取图片实际宽高并根据屏幕尺寸写到swiper的高度,这样实现了自适应,代码如下:
Page({
data: {
imgUrls: [
‘s1.jpg’,
‘s2.jpg’,
‘s3.jpg’
],
imgheights:[],
current:0
},
imgload:function(e){
console.log(wx.getSystemInfoSync().windowWidth)
var imgheight = e.detail.height;
var imgwidth = e.detail.width;
var bl = imgheight / imgwidth;
var sjgd = bl * (wx.getSystemInfoSync().windowWidth);
var hs = this.data.imgheights;
console.log(e);
console.log(sjgd);
hs[e.target.dataset.id] = sjgd;
this.setData({imgheights:hs});
},
bindchange: function (e) {
// console.log(e.detail.current)
this.setData({ current: e.detail.current })
},
})