移动功能在官方实例中已有利用dragPoint实现,不过在开发过程中因为与需求有个冲突bug,所以又重新写了一个利用position.x\y实现的,虽然并没有直接解决不过也记录下吧。哎哎哎哎
官方实例代码:链接
obj.on('mousedown', onDragStart)
.on('touchstart', onDragStart)
.on('mouseup', onDragEnd)
.on('mouseupoutside', onDragEnd)
.on('touchend', onDragEnd)
.on('touchendoutside', onDragEnd)
.on('mousemove', onDragMove)
.on('touchmove', onDragMove);
function onDragStart(event) {
if (!this.dragging) {
this.data = event.data;
this.dragging = true;
this.scale.x *= 1.1;
this.scale.y *= 1.1;
this.dragPoint = event.data.getLocalPosition(this.parent);
this.dragPoint.x -= this.x;
this.dragPoint.y -= this.y;
}
}
function onDragEnd() {
if (this.dragging) {
this.dragging = false;
this.scale.x /= 1.1;
this.scale.y /= 1.1;
this.data = null;
}
}
function onDragMove() {
if (this.dragging) {
var newPosition = this.