
在本教學中,我們將學習如何使用 FabricJS 設定圓的 X 軸傾斜角度。圓形是 FabricJS 提供的各種形狀之一。為了建立一個圓圈,我們將建立一個fabric.Circle類別的實例並將其新增到畫布中。我們的圓圈物件可以透過多種方式自訂,例如更改其尺寸,添加背景顏色或透過改變 X 軸上的傾斜角度。我們可以透過使用 skewX 屬性來做到這一點。
語法
1 | new fabric.Circle({ skewX : Number }: Object)
|
登入後複製
參數
#選項(可選) - 此參數是一個物件< /em> 為我們的圈子提供額外的客製化。使用此參數,可以變更與 skewX 為屬性的物件相關的屬性,例如顏色、遊標、描邊寬度和許多其他屬性。
選項鍵
範例1
>當不應用skewX 屬性時
讓我們看一個範例來了解當不應用skewX屬性時我們的圓形物件如何顯示。在這種情況下,我們的圓形物件不會出現任何角度的扭曲。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <em><!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>Setting the angle of skew on X-axis of circle using FabricJS</h2>
<p>Here we have not applied the <b>skewX</b> property, hence there is no distortion in the object. </p>
<canvas id= "canvas" ></canvas>
<script>
var canvas = new fabric.Canvas( "canvas" );
var circle = new fabric.Circle({
left: 50,
top: 90,
radius: 50,
fill: "#ccccff" ,
stroke: "#7b68ee" ,
strokeWidth: 5
});
canvas.add(circle);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html></em>
|
登入後複製
範例 2
將 skewX 作為鍵傳遞並為其指派自訂值。
在此範例中,我們將了解如何指派skewX 屬性的數值。傳遞的值將確定沿 X 軸的扭曲。由於我們已將 skewX 屬性的值指定為 30,因此效果就好像圓形物件被水平捏過角以形成 30 度角。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <em><!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>Setting the angle of skew on X-axis of circle using FabricJS</h2>
<p>Observe that the object is skewed on the X-axis in the clockwise direction at an angle of 30 degrees, as we have set <b>skewX</b> at 30. </p>
<canvas id= "canvas" ></canvas>
<script>
var canvas = new fabric.Canvas( "canvas" );
var circle = new fabric.Circle({
left: 50,
top: 90,
radius: 50,
fill: "#ccccff" ,
stroke: "#7b68ee" ,
strokeWidth: 5,
skewX: 30
});
canvas.add(circle);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html></em>
|
登入後複製
以上是如何使用 FabricJS 設定圓的 X 軸傾斜角度?的詳細內容。更多資訊請關注PHP中文網其他相關文章!