如何使用 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