Fabric.js - 居中后对象不能 drag/move
Fabric.js - object cannot drag/move after centered
我正在使用 farbric.js 在应用程序中编辑图像。
图像应该能够调整大小、move/drag 和旋转。
问题是当我旋转图像时(通过单击按钮),它不会位于图像的中心 canvas。所以我必须使用 centerObject() 来让它工作。
但是,我这样做之后,图片就不能再拖动了。
这是处理旋转的函数(在class中):
rotationset : function(angle, offsetX, offsetY){
// this.obj is the origin object
this.Obj.left = offsetX;
this.Obj.top = offsetY;
this.Obj.angle = angle;
this.Obj.center();//center the image
//this.canvas also initialized on load.
this.canvas.calcOffset();
this.canvas.renderAll();
}
所以,问题是什么?还有其他解决方法吗?
文档说:
You might need to call setCoords
on an object after centering, to update controls area.
在 this.Obj.center();
之后执行 this.Obj.setCoords();
应该可以解决问题。
我正在使用 farbric.js 在应用程序中编辑图像。 图像应该能够调整大小、move/drag 和旋转。 问题是当我旋转图像时(通过单击按钮),它不会位于图像的中心 canvas。所以我必须使用 centerObject() 来让它工作。 但是,我这样做之后,图片就不能再拖动了。
这是处理旋转的函数(在class中):
rotationset : function(angle, offsetX, offsetY){
// this.obj is the origin object
this.Obj.left = offsetX;
this.Obj.top = offsetY;
this.Obj.angle = angle;
this.Obj.center();//center the image
//this.canvas also initialized on load.
this.canvas.calcOffset();
this.canvas.renderAll();
}
所以,问题是什么?还有其他解决方法吗?
文档说:
You might need to call
setCoords
on an object after centering, to update controls area.
在 this.Obj.center();
之后执行 this.Obj.setCoords();
应该可以解决问题。