微信小程序 圖片寬度自適應(yīng)的實現(xiàn)
實例代碼:
wxml 代碼:
<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>
JS 代碼:
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//監(jiān)聽滾動和點擊事件 }) }
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答