如何使用 FabricJS 隐藏圆形的控制边界?
在本教程中,我们将学习如何使用 FabricJS 隐藏圆形的控制边界。圆形是 FabricJS 提供的各种形状之一。为了创建一个圆形,我们将创建一个`fabric.Circle`类的实例并将其添加到画布中。我们可以通过多种方式自定义控制边界,例如为其添加特定颜色、虚线图案等。但是,我们也可以使用`hasBorders`属性完全消除边界。
语法
new fabric.Circle({ hasBorders: Boolean }: Object)参数
options (可选) − 此参数是一个对象,它为我们的圆形提供了额外的自定义选项。使用此参数,可以更改与对象相关的许多属性,例如颜色、光标、笔划宽度以及`hasBorders`属性。
选项键
hasBorders − 此属性接受一个布尔值,当设置为false时,将不会渲染控制边界。默认值为true。
示例 1
圆形对象的控制边界的默认外观
让我们来看一段代码,该代码显示了圆形控制边界的默认外观。由于`hasBorders`属性的默认值为**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 borders of a circle using FabricJS</h2>
<p>Select the object and notice its controlling borders. This is the default appearance. Although we have not used the <b>hasBorders</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
将hasBorders作为键并为其赋值“false”
如果将`hasBorders`属性赋值为**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 borders of a circle using FabricJS</h2>
<p>Select the object and now you will no longer be able to see its controlling borders, as we have set <b>hasBorders</b> as 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,
hasBorders: false
});
// Adding it to the canvas
canvas.add(circle);
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