
在本教程中,我们将学习如何使用 FabricJS 设置 Circle 的最小允许比例。圆形是 FabricJS 提供的各种形状之一。为了创建一个圆圈,我们必须创建一个 Fabric.Circle 类的实例并将其添加到画布中。我们可以通过添加填充颜色来自定义圆形对象,消除其边框,甚至更改其尺寸。同样,我们还可以使用 minScaleLimit 属性来设置其允许的最小比例。
语法
new fabric.Circle({ minScaleLimit : Number }: Object)参数
选项(可选) - 此参数是一个对象 为我们的圈子提供额外的定制。使用此参数,可以更改与 minScaleLimit 为属性的对象相关的颜色、光标、边框宽度和许多其他属性。
选项键
minScaleLimit - 此属性接受数字 strong> 作为允许我们控制圆的最小允许比例的值。
示例 1
默认圆形对象的外观
让我们看一下代码,看看当不使用 minScaleLimit 属性时,圆形对象是什么样子。在这种情况下,我们将能够自由缩放对象,因为没有设置最小限制。
Setting the minimum allowed scale value of circle using FabricJS
Select the object and scale it down by dragging one of its controlling corners. Here you can scale down the object freely since there is no minimum limit set.
示例 2
将 minScaleLimit 属性作为带有自定义值的键传递
在此示例中,我们将看到为 minScaleLimit 属性赋值如何更改画布中圆形对象的最小允许比例值。这里我们使用 0.8 作为值,这意味着我们将无法将对象缩小到半径小于 64 像素的半径,该半径是通过半径 * 限制计算的(0.8 * 80 = 64 像素)。
Setting the minimum allowed scale value of circle using FabricJS
Select the object and try to scale it down by dragging one of its controlling corners. You cannot scale down the object freely, as we have set minScaleLimit at 0.8. So, the minimum scale of the circle must be at least 80% of the original radius, beyond which you cannot scale it down any further.










