如何使用 FabricJS 設定橢圓在 Y 軸上的傾斜角度?
在本教程中,我們將學習如何使用 FabricJS 設定橢圓在 Y 軸上的傾斜角度。橢圓是 FabricJS 提供的各種形狀之一。為了建立橢圓,我們將必須建立一個 fabric.Ellipse 類的例項並將其新增到畫布上。我們的橢圓物件可以透過多種方式進行自定義,例如更改其尺寸、新增背景顏色或更改 Y 軸上的傾斜角度。我們可以使用 skewY 屬性來實現這一點。
語法
new fabric.Ellipse({ skewY : Number }: Object)引數
options (可選) - 此引數是一個 物件,它為我們的橢圓提供了額外的自定義選項。使用此引數,可以更改與物件相關的許多屬性,例如顏色、游標、描邊寬度,其中 skewY 就是一個屬性。
選項鍵
skewY - 此屬性接受一個 數字,用於確定物件在 Y 軸上的傾斜角度。
示例 1
當未應用 skewY 屬性時
讓我們看一段程式碼來了解當未應用 skewY 屬性時,我們的橢圓物件是如何顯示的。在這種情況下,我們的橢圓物件將沒有傾斜。
<!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 set the angle of skew on Y-axis of Ellipse using FabricJS?</h2>
<p>Notice there is no angle of skew here as we have not applied the <b>skewX</b> or <b>skewY</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: 80,
ry: 50,
fill: "#ff1493",
});
// Adding it to the canvas
canvas.add(ellipse);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>示例 2
將 skewY 作為鍵併為其分配自定義值。
在本例中,我們將看到如何為 skewY 屬性分配數值。傳遞的值將決定沿 Y 軸的傾斜程度。
<!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 set the angle of skew on y-axis of Ellipse using FabricJS?</h2>
<p>Here the ellipse is skewed on the Y-axis by 30 degrees, as we have applied the <b>skewY</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: 80,
ry: 50,
fill: "#ff1493",
skewY: 30,
});
// 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