我想在触摸设备上平移画布的视口,我编写了以下代码:
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;
}
});