微信小程式swiper元件實現圖片寬度自適應
阿新 • • 發佈:2019-01-23
微信小程式 圖片寬度自適應的實現
例項程式碼:
wxml 程式碼:
JS 程式碼:<swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}"> <block wx:for="{{imgUrls}}" wx:key="image"> <swiper-item> <image src="{{item.image}}" model="aspectFit" style="width: {{imageWidth}}px;" bindload="imageLoad" /> </swiper-item> </block> </swiper>
imageLoad: function () { this.setData({ imageWidth: wx.getSystemInfoSync().windowWidth,//圖片寬度 imgUrls: [ { image: "http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg" }, { image: "http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg" }, { image: "http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg" }], indicatorDots: false,//是否顯示圓點 autoplay: true,//自動播放 interval: 2000,//間隔時間 duration: 1000//監聽滾動和點選事件 }) }