网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

微信小程序movable-view移動圖片和雙指縮放

發布時間:2018-04-23 11:46 所屬欄目:小程序開發教程
 1 <view class="section">
 2   <view class="section__title">movable-view區域小于movable-areaview>
 3   <movable-area style="height: 200px;width: 200px;background: red;">
 4     <movable-view style="height: 50px; width: 50px; background: blue;" x="{{x}}" y="{{y}}" direction="all">
 5     movable-view>
 6   movable-area>
 7   <view class="btn-area">
 8     <button size="mini" bindtap="tap">click me to move to (30px, 30px)button>
 9   view>
10   <view class="section__title">movable-view區域大于movable-areaview>
11   <movable-area style="height: 100px;width: 100px;background: red;" direction="all">
12     <movable-view style="height: 200px; width: 200px; background: blue;">
13     movable-view>
14   movable-area>
15 view>

這里面有個錯誤,應該是編寫人的一點小失誤吧. 第二個movable-area的屬性direction應該寫在movable-view上.

1   
2           <view class="flex-wrap flex-pic">
3               <view class="picList">            
4                   
for="{{item.imglist}}" wx:for-item="itemImg" wx:key="*this" id="{{'rfnd_'+index}}" bindload="imageOnload" src="{{ itemImg}}" bindtap="showResizeModal" data-src="{{itemImg}}"> 5 view> 6 view>

因為要查看的是一個圖片列表, 我用了一個數組去存儲每個圖片的寬高,然后通過圖片id來關聯

 1   /**
 2    * 加載圖片
 3    */
 4   imageOnload:function(e){
 5     var id = e.currentTarget.id
 6     this.data.imgIdList[id] = {
 7       width:e.detail.width,
 8       height:e.detail.height
 9     }
10     
11   },

模板頁面

 1 
 3 <template name="resizePic">
 4 
 5   <scroll-view class="backdrop"> 
 6     <view class="close-icon" bindtap="closeResizeModal"> 
 7       取消預覽
 8     view>
 9     <movable-area style="width:100%;height:100%;"  >
10         <movable-view direction="all" 
11         out-of-bounds="true"  x="{{img.x}}" y="{{img.y}}" >
12         <image  mode="widthFix" class="dtl-img" src="{{img.currentSrc}}">image>
13         movable-view>
14         
15     movable-area> 
16   scroll-view> 
17  template>
 1   /**
 2    * 打開彈窗
 3    */
 4   showResizeModal: function (e) {
 5     var src = e.currentTarget.dataset.src;
 6     var x = 0
 7     var y =0
 8     try {
 9       var width = this.imgIdList[e.currentTarget.id].width; //圖片原寬
10       var height = this.imgIdList[e.currentTarget.id].height; //圖片原高
11      
12       //小程序默認固定寬320px,獲取top和left值,使圖片居中顯示
13       height = height * (320 / width);
14       width = 320;
15     
16       x = (app.windowWidth - width) / 2 
17       y = (app.windowHeight - height) / 2
18 
19     } catch (e) { }
20     var img = {
21       x: x,
22       y: y,
26      currentSrc: src,
27     };
28     this.setData({ img: img, isCheckDtl: true });
29     
30   },

部分CSS代碼

.backdrop{
  background: rgba(0, 0, 0, 1);
  width:100%;
  height: 100%;
  position: fixed;
  top:0;
  left:0;
}

以上基本上可以完成一個點擊查看圖片的需求.

然而如果再支持雙指縮放的話,movable-view實現不了.我暫沒想出來怎么實現,如果有人知道,希望能夠指點迷津. 主要原因是因為還是我上文提到的那句話:”movable組件加載成功后再去改變movable-view的大小,可移動區域是不會變的”.縮放后圖片大小肯定會改變的. 縮小還好,一旦放大,可移動區域還是原來的不會改變.想象一下,如果一張寬度剛剛好時屏幕可視寬度的圖片,放大后,這張圖片就只能在屏幕可視寬度windowWidth的范圍中移動,看不到左也看不到右邊超出的部分.

所以如果既要可移動圖片又要可縮放,就不能用movable-view組件了,自己寫個吧. 原來bindtouchmove會觸發頁面的滾動條,但是現在微信好像已經修復了這個BUG,我今天在真機上測試沒有出現這個問題.

自定義控件resizePicModal.wxml:

 1 
 2 <template name="resizePic">
 3   <scroll-view class="backdrop"  catchtouchmove="bindTouchMove" catchtouchend="bindTouchEnd" bindtouchstart="bindTouchStart" > 
 4     <view class="close-icon" bindtap="closeResizeModal"> 
 5       取消預覽
 6     view>
 7        <image catchtouchmove="bindTouchMove" bindtouchend="bindTouchEnd" bindtouchstart="bindTouchStart"  
 8       style=" transform: scale({{img.baseScale}}); position:absolute; top:{{img.top}}px; left:{{img.left}}px; "
 9       mode="widthFix" class=


易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/23923.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×