如何使用 FabricJS 隐藏椭圆的控制边框?
在本教程中,我们将学习如何使用 FabricJS 隐藏椭圆的控制边框。椭圆是 FabricJS 提供的各种形状之一。为了创建椭圆,我们将必须创建一个 fabric.Ellipse 类的实例并将其添加到画布中。我们可以通过多种方式自定义我们的控制边框,例如向其添加特定的颜色、虚线模式等。但是,我们也可以使用 hasBorders 属性完全消除边框。
语法
new fabric.Ellipse({ 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>How to hide the controlling borders of an Ellipse using FabricJS?</h2>
<p>Select the object and you would get to see the controlling borders. This is the default behavior.</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: 105,
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
将 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>How to hide the controlling borders of an Ellipse using FabricJS?</h2>
<p>Select the object. Now you won't get to see the controlling borders because we have set the <b>hasBorders</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: 105,
top: 100,
fill: "white",
rx: 100,
ry: 60,
stroke: "#c154c1",
strokeWidth: 5,
hasBorders: false,
});
// Adding it to the canvas
canvas.add(ellipse);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP