微信小程式開發圖片拖拽執行個體詳解,程式開發拖拽

來源:互聯網
上載者:User

小程式開發圖片拖拽執行個體詳解,程式開發拖拽

小程式開發圖片拖拽執行個體詳解

1.編寫頁面結構:moveimg.wxml

<view class="container">   <view class="cnt">     <image class="image-style" src="../uploads/foods.jpg" style="left:{{ballleft}}px;width:{{screenWidth}}px" bindtouchmove="ballMoveEvent">     </image>   </view> </view> 

2.編寫頁面樣式:moveimg.wxss

.container {   box-sizing:border-box;   padding:1rem; } .cnt{   width:100%;   height:15rem;   border: 1px solid #ccc;   position:relative;   overflow: hidden; } .image-style{    position: absolute;    top: 0px;    left:0px;    height:100%;  }  

3.設定資料:moveimg.js

var app = getApp() Page({   data: {     ballleft:-20,     screenWidth: 0,   },   onLoad: function() {     var _this = this;     wx.getSystemInfo({       success: function(res) {         _this.setData({           screenHeight: res.windowHeight,           screenWidth: res.windowWidth,         });       }     });    },   ballMoveEvent: function(e) {     var touchs = e.touches[0];     var pageX = touchs.pageX;     console.log('寬度 '+this.data.screenWidth)     console.log('pageX: ' + pageX);     //這裡用right和bottom.所以需要將pageX pageY轉換      var x = this.data.screenWidth/2 - pageX-20;     if(this.data.screenWidth>385){       if(x>42){x=42;}     }else{       if(x>32){x=32;}     }     if(x<0){x=0;}     console.log('x:' + x)     this.setData({       ballleft: -x     });   } }) 

   這幾天一直在研究圖片裁剪,思路是有,可是卻遇到各種問題。可憐編程不易啊。

想了好久,決定還是簡單開始吧。如果大家有更好的方式或是其他想法,歡迎提出,一起討論。

感謝閱讀,希望能協助到大家,謝謝大家對本站的支援!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.