Fabric.js 椭圆 top 属性
在本文中,我们将看到如何使用FabricJS相对于顶部定位画布上的椭圆。画布上的椭圆可移动,并可以根据需求进行拉伸。此外,当涉及到初始描边颜色、填充颜色、描边宽度或半径时,椭圆可以进行自定义。
为了实现这一点,我们将使用一个称为FabricJS的JavaScript库。在使用CDN导入库之后,我们将在标签中创建一个块,其中包含我们的椭圆。之后,我们将初始化由FabricJS提供的Canvas和Ellipse实例,并使用 strokeWidth 属性将画布上的椭圆相对于顶部定位,并将椭圆呈现在画布上,如下面的示例所示。
语法:
fabric.Ellipse({
rx: number,
ry: number,
stroke: string,
strokeWidth: number
});
参数: 此函数接受三个参数,如上所述,并如下所述:
- rx: 它指定了水平半径。
- ry: 它指定了垂直半径。
- top: 它指定了椭圆相对于顶部的位置。
示例: 此示例使用FabricJS将画布椭圆相对于顶部进行定位。
<!DOCTYPE html>
<html>
<head>
<title>
Fabric.js | Ellipse top Property
</title>
<!-- FabricJS CDN -->
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js">
</script>
</head>
<body>
<div style="text-align: center;width: 600px;">
<h1 style="color: green;">
GeeksforGeeks
</h1>
<b>
Fabric.js | Ellipse top Property
</b>
</div>
<div style="text-align: center;">
<canvas id="canvas" width="600" height="200"
style="border:1px solid #000000;">
</canvas>
</div>
<script>
// Initiate a Canvas instance
var canvas = new fabric.Canvas("canvas");
// Initiate a Ellipse instance
var ellipse = new fabric.Ellipse({
rx: 80,
ry: 40,
top: 90
});
// Render the Ellipse in canvas
canvas.add(ellipse);
</script>
</body>
</html>
输出: