微信小程序轮播中的current_微信小程序轮播图自适应实现

  • Post author:
  • Post category:小程序


在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 })

},

})



版权声明:本文为weixin_39540934原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。