微信小程序 catchtouchstart、catchtouchmove的使用 移動不會產生偏移

wxml:

<image src="" mode="widthFix" data-i="0" catchtouchstart='emoveimg' catchtouchmove='emoveimg' catchtouchend='emoveimg'></image>

js:

emoveimg: function (e) {
    let index = e.currentTarget.dataset.i,point = this.data.pointarea;
    if(e.type=="touchstart"){
      this.pointx = e.changedTouches[0].pageX;
      this.pointy = e.changedTouches[0].pageY;
      return;
    }
    let cx = e.changedTouches[0].pageX,cy = e.changedTouches[0].pageY;
    cx = cx - this.pointx;
    cy = cy - this.pointy;
    point[index].x = point[index].x + cx;
    point[index].y = point[index].y + cy;
    if(point[index].x<0||point[index].x>235){
      point[index].x = point[index].x - cx;
    }
    if(point[index].y<0||point[index].y>235){
      point[index].y = point[index].y - cy;
    }
    this.pointx = e.changedTouches[0].pageX;
    this.pointy = e.changedTouches[0].pageY;
    this.setData({pointarea:point})
  },

pointarea爲圖片位置

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章