我想在触摸设备上平移画布的视口,我写了这段代码:
canvas.on('touch:drag', function (opt) {
var e = opt.e;
if (this.isDragging) {
if (e.clientX === undefined ) {
this.isDragging = false;
} else {
this.viewportTransform[4] += e.clientX - this.lastPosX;
this.viewportTransform[5] += e.clientY - this.lastPosY;
this.requestRenderAll();
this.lastPosX = e.clientX;
this.lastPosY = e.clientY;
}
} else {
this.isDragging = true;
this.selection = false;
this.lastPosX = e.clientX;
this.lastPosY = e.clientY;
}
});
这适用于我的台式机,但不适用于我的智能手机(视口不动):你知道为什么吗?
在触摸设备中,通常你有e.touches[0].clientX
而不是e.clientX