微信小程序中图片宽度自适应的有效实现途径

why 150 2024-08-15

这篇文章主要介绍了微信小程序 图片宽度自适应的实现的相关资料,需要的朋友可以参考下

微信小程序中图片宽度自适应的有效实现途径

 微信小程序 图片宽度自适应的实现

实例代码:

wxml 代码:


1

2

3

4

5

6

7

<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 代码:


1

2

3

4

5

6

7

8

9

10

11

12

13

14

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//监听滚动和点击事件

 })

}


以上就是本文的全部内容,希望对大家的学习有所帮助。


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:有关微信小程序中弹框与模态框的实现方式探讨
下一篇:微信小程序image组件binderror使用实例与js中onerror的差异剖析
相关文章

 发表评论

暂时没有评论,来抢沙发吧~