【微信小程序】微信小程序wx.previewImage預覽圖片


  一.小知識

二.例子,配合輪播圖使用效果更佳!(如圖1)

1.wxml

<scroll-view  scroll-y="true">
      <swiper  catchtap="onSwiperTap" autoplay="auto" interval="3000" duration="500" current="{{swiperCurrent}}"  bindchange="swiperChange">
          <block wx:for="{{home_pics}}" wx:for-item="image"   wx:for-index="index">
              <swiper-item>
        <image src="{{image}}" data-src="{{image}}" bindtap="previewImage"></image>
              </swiper-item>
          </block>
      </swiper>

2.wxss

<span style="font-family:Comic Sans MS;font-size:18px;color:#333333;">.container {
    box-sizing:border-box;
    padding:20px;
} 
.previewimg{
    float:left;
    width:45%;
    height:200px;
    margin:2%;
}
.previewimg image{
    width:100%;
    height:100%;
}</span>

3.js

使用網絡的圖

var app = getApp()  
Page({
    data: {  
       imgalist:[ 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1496287851&di=0a26048f586b8521
       93cb5026d60c4fad&imgtype=jpg&er=1&src=http%3A%2F%2Fpic.58pic.com%2F58pic%2F12%2F74%2F05%2F99C58PICYck.jpg',
       'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1495693185413&di=0d0acdebf0f532edd0fcdb7
       6265623c5&imgtype=0&src=http%3A%2F%2Fimg1.3lian.com%2Fimg013%2Fv3%2F2%2Fd%2F61.jpg', 
    ]},
    /** 
     * 預覽圖片
     */
    previewImage: function (e) {  
        var current=e.target.dataset.src;
        wx.previewImage({
              current: current, // 當前顯示圖片的http鏈接
              urls: this.data.imgalist // 需要預覽的圖片http鏈接列表
        })
    }  
})

     

          圖1

   

            圖2   

 

注意:

網上還有說本地圖片確實是不可以的,后面通過選取手機相冊內的照片,可以預覽,前提是在真機上演示。 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM