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为图片位置