
在本文中,我们将学习如何使用 FabricJS 设置画布上选择区域的颜色。我们可以使用selectionColor属性调整颜色。
语法
new fabric.Canvas(element: HTMLElement|String, { selectionColor: String }: Object)参数
元素 - 此参数是
选项(可选) - 此参数是一个对象,它提供对我们的画布进行额外的定制。使用此参数,可以更改与画布相关的颜色、光标、边框宽度等属性以及许多其他属性,其中selectionColor是我们可以指示选区颜色的属性。 SelectionColor的默认值为rgba(100,100,255,0.3)。
示例1
将selectionColor键传递给类
selectionColor 属性接受一个确定所选内容颜色的字符串。我们可以使用 RGBA 值,它代表:红、蓝、绿和 alpha。 alpha 参数指定颜色的不透明度。让我们看一个代码示例,了解如何使用 FabricJS 设置画布中选择区域的颜色。
Setting the color of a selection area using FabricJs
Select an area around the object to see the color of the selection area.
示例 2
使用颜色名称代替 RGBA 值
我们还可以使用特定颜色代替 RGBA 值。在此示例中,selectionColor 属性已设置为颜色“红色”。
Setting the color of a selection area using FabricJs
Select an area around the object to see the color of the selection area.










