
在本文中,我们将学习如何使用 FabricJS 仅当对象完全包含在选择区域中时才启用对象的选择。我们可以使用 SelectionFullyContained 属性来实现此目的。
语法
new fabric.Canvas(element: HTMLElement|String, { selectionFullyContained: Boolean }: Object)参数
元素 - 此参数是
选项(可选) - 此参数是一个对象,它提供对我们的画布进行额外的定制。使用此参数,可以更改与画布相关的颜色、光标、边框宽度和许多其他属性,其中selectionFullyContained 是一个属性。它接受一个布尔值,该值确定是否仅当对象完全包含在选择区域中时才应选择该对象。默认值为 False。
示例 1
传递值为 False 的 SelectionFullyContained 键
让我们看一下 FabricJS 中默认行为的代码示例,即尽管对象未完全包含在选择区域中,但对象仍被选中。在此示例中,我们将 SelectionFullyContained 的值传递为 False。
Enabling selection of an object only when it is fully contained in a selection area
Select a partial area around the object. The entire object would be selected even if you select a partial area containing the object.
示例2
将selectionFullyContained键传递给值为True的类
让我们看一个代码示例,其中selectionFullyContained属性的值具有已设置为 True。正如我们所看到的,只有当对象完全包含在选择区域中时才会选择该对象。
Enabling selection of an object only when it is fully contained in a selection area
Here you cannot select the object by selecting a partial area around the object. The object must be fully contained inside the selection area.










