如何使用 FabricJS 使椭圆的控制角透明?
在本教程中,我们将学习如何使用 FabricJS 使椭圆的控制角透明。椭圆是 FabricJS 提供的各种形状之一。为了创建一个椭圆,我们将创建一个 *fabric.Ellipse* 类的实例并将其添加到画布中。*transparentCorners* 属性允许我们将椭圆的控制角设置为透明。
语法
new fabric.Ellipse( { transparentCorners: Boolean }: Object)参数
options (可选) − 此参数是一个 *对象*,它为我们的椭圆提供了额外的自定义选项。使用此参数,可以更改与对象相关的许多属性,例如颜色、光标、笔划宽度,其中 *transparentCorners* 就是一个属性。
选项键
transparentCorners − 此属性接受一个 **布尔值**,允许我们将对象的控制角渲染为透明。其默认值为 **True**。
示例 1
将 *transparentCorners* 属性作为键,值为 'false'
让我们来看一段代码,创建一个控制角不透明的椭圆对象。为此,我们需要将 *transparentCorners* 属性设置为 "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 make controlling corners of Ellipse transparent using FabricJS?</h2>
<p>Select the object and you will notice that the controlling corners are not transparent. Here we have set the <b>transparentCorners</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: 115,
top: 50,
rx: 100,
ry: 70,
fill: "red",
transparentCorners: false,
});
// Adding it to the canvas
canvas.add(ellipse);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>示例 2
将 *transparentCorners* 属性作为键,值为 'true'
在这个例子中,我们将 *transparentCorners* 属性设置为 "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>Making the controlling corners of an Ellipse transparent using FabricJS</h2>
<p>Select the object and you will notice that its controlling coners are now transparent as we have applied the <b>transparentCorners</b> property. </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: 115,
top: 50,
rx: 100,
ry: 70,
fill: "red",
transparentCorners: true,
});
// 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