微信小程序開發(fā)圖片拖拽的示例分析

這篇文章給大家分享的是有關(guān)微信小程序開發(fā)圖片拖拽的示例分析的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

從事大邑服務(wù)器托管,服務(wù)器租用,云主機(jī),網(wǎng)頁空間,國際域名空間,CDN,網(wǎng)絡(luò)代維等服務(wù)。

微信小程序開發(fā)圖片拖拽實例詳解

微信小程序開發(fā)圖片拖拽的示例分析

1.編寫頁面結(jié)構(gòu):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.設(shè)置數(shù)據(jù):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轉(zhuǎn)換  
    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 
    }); 
  } 
})

感謝各位的閱讀!關(guān)于“微信小程序開發(fā)圖片拖拽的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

網(wǎng)站題目:微信小程序開發(fā)圖片拖拽的示例分析
文章網(wǎng)址:http://bm7419.com/article18/igcogp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、自適應(yīng)網(wǎng)站、關(guān)鍵詞優(yōu)化、網(wǎng)站收錄用戶體驗、網(wǎng)站營銷

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)