
在本教程中,我们将学习如何使用 FabricJS 禁用 Rectangle 的居中旋转。矩形是 FabricJS 提供的各种形状之一。为了创建一个矩形,我们必须创建一个 Fabric.Rect 类的实例并将其添加到画布中。默认情况下,FabricJS 中的所有对象都使用其中心作为旋转点。但是,我们可以使用 centeredRotation 属性来更改此行为。
语法
new fabric.Rect({ centeredRotation: Boolean }: Object)参数
选项(可选) - 此参数是一个提供额外自定义的对象到我们的矩形。使用此参数,可以更改与 centeredRotation 属性相关的对象的颜色、光标、描边宽度等属性。
centeredRotation - 该属性接受一个布尔值,允许我们可以通过控件来控制对象旋转时是否使用中心点作为其变换原点。它的默认值为True。
选项键
示例1
FabricJS中矩形旋转的默认行为
让我们看一个描述矩形对象默认行为的代码示例。由于 centeredRotation 属性默认设置为 true,因此矩形对象使用其中心作为旋转点。Default behaviour of rotation of Rectangle in FabricJS
Click on the rectangle and rotate it. You will notice that the object rotates around its center, which is the default behaviour.
示例 2
传递值为“false”的 centeredRotation 键
现在我们已经看到了默认行为,让我们看一下代码示例,以了解为 centeredRotation 属性分配 False 值时会发生什么。
Passing centeredRotation key with the value as “false”
Click on the rectangle and rotate it to see the changed center of rotation










