国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

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

2019-11-19 16:39:53
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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

1.編寫頁(yè)面結(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.編寫頁(yè)面樣式: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     });   } }) 

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

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

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 蓬莱市| 金秀| 石台县| 延安市| 鄂尔多斯市| 广汉市| 比如县| 綦江县| 资兴市| 温州市| 新竹县| 桐城市| 万山特区| 望江县| 拜泉县| 孝昌县| 乐至县| 楚雄市| 富源县| 康定县| 平乡县| 南投市| 蕉岭县| 韶关市| 故城县| 巧家县| 荣昌县| 交城县| 罗江县| 太康县| 贵溪市| 平安县| 南安市| 鹿邑县| 雷波县| 汨罗市| 会同县| 抚顺市| 海兴县| 韩城市| 防城港市|