如何使用 FabricJS 隐藏圆形的控制角?
在本教程中,我们将学习如何使用 FabricJS 隐藏圆形的控制角。圆形是 FabricJS 提供的各种形状之一。为了创建一个圆形,我们必须创建一个 fabric.Circle 类的实例并将其添加到画布上。对象的控制角允许我们增加或减少其比例、拉伸或更改其位置。我们可以通过多种方式自定义我们的控制角,例如为其添加特定的颜色、更改其大小等。但是,我们也可以使用 hasControls 属性隐藏它们。
语法
new fabric.Circle({ hasControls: Boolean }: Object)参数
options(可选) - 此参数是一个 Object,它为我们的圆形提供了额外的自定义。使用此参数,可以更改与对象的 hasControls 属性相关的属性,例如颜色、光标、笔触宽度以及许多其他属性。
选项键
hasControls - 此属性接受一个 布尔值,允许我们显示或隐藏活动选择对象的控制角。其默认值为 True。
示例 1
控制角的默认外观
让我们看看一段代码,它显示了控制角的默认外观。由于 hasControls 属性的默认值为 True,因此控制角不会被隐藏。
<!DOCTYPE html>
<html>
<head>
<!-- Adding the Fabric JS Library-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script>
</head>
<body>
<h2>Hiding the controlling corners of a circle using FabricJS</h2>
<p>Select the object and observe its controlling corners. This is the default appearnce. Even though we have not applied the <b>hasControls</b> property, it is by default set to True. </p>
<canvas id="canvas"></canvas>
<script>
// Initiate a canvas instance
var canvas = new fabric.Canvas("canvas");
var circle = new fabric.Circle({
left: 215,
top: 100,
fill: "white",
radius: 50,
stroke: "#c154c1",
strokeWidth: 5
});
// Adding it to the canvas
canvas.add(circle);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>示例 2
将 hasControls 作为键并为其分配“false”值
在本例中,我们将看到如何使用 hasControls 属性隐藏控制角。我们需要为 hasControls 键分配一个 'false' 值。通过这样做,控制角将被隐藏。
<!DOCTYPE html>
<html>
<head>
<!-- Adding the Fabric JS Library-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script>
</head>
<body>
<h2>Hiding the controlling corners of a circle using FabricJS</h2>
<p>Select the object and you will notice that the controlling corners are no longer there. Here we have set <b>hasControls</b> to False.</p>
<canvas id="canvas"></canvas>
<script>
// Initiate a canvas instance
var canvas = new fabric.Canvas("canvas");
var circle = new fabric.Circle({
left: 215,
top: 100,
fill: "white",
radius: 50,
stroke: "#c154c1",
strokeWidth: 5,
hasControls: false
});
// Adding it to the canvas
canvas.add(circle);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP