二十五、小程序的图片预览(放大滑动)

注意:好像图片必须在服务器上才可以浏览(我是这样的)

WXML

<view class='imgList'>      
  <view class='imgList-li' wx:for='{{imgArr}}'>
    <image class='img' src='{{item}}' data-index='{{index}}' bindtap='previewImg'></image>
  </view>
</view>

  WCSS

.imgList{
  width: 100%;
}
.imgList .imgList-li{
  width: 100%;
}
.imgList .imgList-li .img{
  width: 400rpx;
  height: 400rpx;
}

  JS

Page({
  data: {
    imgArr: [ 'http://bpic.588ku.com/element_origin_min_pic/16/10/30/528aa13209e86d5d9839890967a6b9c1.jpg',
'http://bpic.588ku.com/element_origin_min_pic/16/10/30/54fcef525fa8f6037d180f3c26f3be65.jpg',      'http://bpic.588ku.com/element_origin_min_pic/16/10/30/62e3ca3a02dddb002eff00482078d194.jpg', 'http://bpic.588ku.com/element_origin_min_pic/16/10/31/c7167fcfb4ebcd12621c05b0c852e98e.jpg',
'https://ttcf.njpzd.com/static/beauty/beautyindex/bty01.png'
    ]
  },
  previewImg: function (e) {
    console.log(e.currentTarget.dataset.index);
    var index = e.currentTarget.dataset.index;
    var imgArr = this.data.imgArr;
    wx.previewImage({
      current: imgArr[index],     //当前图片地址
      urls: imgArr,               //所有要预览的图片的地址集合 数组形式
    })
  }
})

  

猜你喜欢

转载自www.cnblogs.com/deng-jie/p/9247020.html
今日推荐