如何使用 FabricJS 垂直翻轉圓形?
在本教程中,我們將學習如何使用 FabricJS 垂直翻轉圓形物件。圓形是 FabricJS 提供的各種形狀之一。為了建立圓形,我們將必須建立一個 fabric.Circle 類的例項並將其新增到畫布上。我們可以使用 flipY 屬性垂直翻轉圓形物件。
語法
new fabric.Circle({ flipY: Boolean }: Object)引數
options(可選) - 此引數是一個 物件,它為我們的圓形提供額外的自定義。使用此引數,可以更改與物件的 flipY 屬性相關的顏色、游標、筆劃寬度和許多其他屬性。
選項鍵
flipY - 此屬性接受布林值。它允許我們垂直翻轉物件。
示例 1
將 flipY 作為鍵並傳遞 'false' 值
讓我們看一個示例,它向我們展示了 FabricJS 中圓形物件的預設方向。由於我們將 flipY 屬性傳遞了一個 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 flip a Circle vertically using FabricJS?</h2>
<p>This is the default orientation of the object. We have set <b>flipY</b> as False, but even if we don't use it, <b>flipY</b> will be by default set to False. </p>
<canvas id="canvas"></canvas>
<script>
// Initiate a canvas instance
var canvas = new fabric.Canvas("canvas");
var circle = new fabric.Circle({
left: 215,
top: 50,
fill: "green",
radius: 80,
stroke: "#228b22",
strokeWidth: 2,
flipY: false
});
// Create gradient fill
circle.set("fill", new fabric.Gradient({
type: "linear",
coords: {
x1: 0,
y1: 0,
x2: 0,
y2: 50
},
colorStops: [{
offset: 0,
color: "red"
}, {
offset: 1,
color: "green"
}, ],
}));
// Adding them to the canvas
canvas.add(circle);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>示例 2
將 flipY 屬性作為鍵並傳遞 'true' 值
在此示例中,我們有一個半徑為 80px 且具有垂直線性漸變填充的圓形物件。當我們將 flipY 屬性應用於圓形物件時,它會垂直翻轉,因此我們看到漸變也翻轉了。
<!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 flip a Circle vertically using FabricJS?</h2>
<p>Here observe that the circle has flipped vertically (see the gradient), as we have set <b>flipY</b> to True.</p>
<canvas id="canvas"></canvas>
<script>
// Initiate a canvas instance
var canvas = new fabric.Canvas("canvas");
var circle = new fabric.Circle({
left: 215,
top: 50,
fill: "green",
radius: 80,
stroke: "#228b22",
strokeWidth: 2,
flipY: true
});
// Create gradient fill
circle.set("fill", new fabric.Gradient({
type: "linear",
coords: {
x1: 0,
y1: 0,
x2: 0,
y2: 50
},
colorStops: [{
offset: 0,
color: "red"
}, {
offset: 1,
color: "green"
}, ],
}));
// Adding them to the canvas
canvas.add(circle);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP