
在本教程中,我们将学习如何使用 FabricJS 设置圆的水平比例因子。圆形是 FabricJS 提供的各种形状之一。为了创建一个圆圈,我们必须创建一个 Fabric.Circle 类的实例并将其添加到画布中。正如我们可以指定圆形对象在画布中的位置、颜色、不透明度和尺寸一样,我们也可以设置圆形对象的水平比例。这可以通过使用 scaleX 属性来完成。
语法
new fabric.Circle({ scaleX : Number }: Object)参数
选项(可选) - 此参数是一个对象 为我们的圈子提供额外的定制。使用此参数,可以更改与 scaleX 为属性的对象相关的颜色、光标、描边宽度和许多其他属性等属性。
ul>scaleX - 此属性接受数字值。分配的值决定水平对象比例因子。其默认值为 1。
选项键
示例 1
未使用 scaleX 时的默认外观
让我们看一下在未使用 scaleX 属性时显示圆形对象外观的代码。默认情况下,圆形对象的水平比例因子为 1。scaleX 确定沿 X 轴调整对象大小的变换。
Setting the horizontal scale factor of circle using FabricJS
This is the default horizontal scale factor. We have not used the scaleX property, but by default, it is set to 1.
示例 2
将 scaleX 属性作为键传递
在此示例中,我们传递 scaleX 属性作为键,值为 2。这意味着圆形对象在水平方向的比例因子加倍。
Setting the horizontal scale factor of circle using FabricJS
Notice the horizontal scale factor of the object. Here we have set scaleX at 2, so the object appears stretched in the horizontal direction.










