这篇文章给大家分享的是有关微信小程序中图片宽度自适应怎么弄的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
微信小程序 图片宽度自适应的实现
实例代码:
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//监听滚动和点击事件
})
}
感谢各位的阅读!关于“微信小程序中图片宽度自适应怎么弄”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!