如何使用 FabricJS 隐藏椭圆的控制角?
在本教程中,我们将学习如何使用 FabricJS 隐藏椭圆的控制角。椭圆是 FabricJS 提供的各种形状之一。为了创建椭圆,我们必须创建一个fabric.Ellipse类的实例并将其添加到画布中。对象的控制角允许我们增加或减少其比例、拉伸或更改其位置。我们可以通过多种方式自定义控制角,例如为其添加特定颜色、更改其大小等。但是,我们也可以使用hasControls属性来隐藏它们。
语法
new fabric.Ellipse({ hasControls: Boolean }: Object)参数
options (可选) − 此参数是一个对象,它为我们的椭圆提供额外的自定义。使用此参数,可以更改与对象的许多属性相关的颜色、光标、描边宽度和其他属性,其中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>How to hide the controlling corners of an Ellipse using FabricJS?</h2>
<p>Select the object to see its controlling corners.</p>
<canvas id="canvas"></canvas>
<script>
// Initiate a canvas instance
var canvas = new fabric.Canvas("canvas");
// Initiate an ellipse instance
var ellipse = new fabric.Ellipse({
left: 100,
top: 100,
fill: "white",
rx: 100,
ry: 60,
stroke: "#c154c1",
strokeWidth: 5,
});
// Adding it to the canvas
canvas.add(ellipse);
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>How to hide the controlling corners of an Ellipse using FabricJS?</h2>
<p>Select the object and here you won't be able to see the controlling corners as we have set the <b>hasControls</b> property to False. </p>
<canvas id="canvas"></canvas>
<script>
// Initiate a canvas instance
var canvas = new fabric.Canvas("canvas");
// Initiate an ellipse instance
var ellipse = new fabric.Ellipse({
left: 100,
top: 100,
fill: "white",
rx: 100,
ry: 60,
stroke: "#c154c1",
strokeWidth: 5,
hasControls: false,
});
// Adding it to the canvas
canvas.add(ellipse);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP