Fabric.js 椭圆 strokeWidth 属性
在本文中,我们将了解如何使用FabricJS设置画布椭圆的笔画宽度。画布上的椭圆可以移动,并且可以根据需要进行拉伸。此外,当涉及到初始笔画颜色、填充颜色、笔画宽度或半径时,可以自定义椭圆。
为了实现这一点,我们将使用一个名为FabricJS的JavaScript库。在使用CDN导入库后,我们将在body标签中创建一个块,它将包含我们的椭圆。在此之后,我们将使用FabricJS提供的Canvas和Ellipse实例化,并使用strokeWidth属性设置画布椭圆的笔画宽度,然后在画布上渲染椭圆,如下面的示例所示。
语法:
fabric.Ellipse({
rx: number,
ry: number,
stroke: string,
strokeWidth: number
});
参数: 此函数接受四个参数,如上所述和描述如下:
- rx: 它指定水平半径。
- ry: 它指定垂直半径。
- stroke: 它指定描边颜色。
- strokeWidth: 它指定描边宽度。
示例: 此示例使用FabricJS来设置画布椭圆的描边宽度。
<!DOCTYPE html>
<html>
<head>
<title>
Fabric.js | Ellipse strokeWidth 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 strokeWidth 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,
stroke: 'red',
strokeWidth: 10
});
// Render the Ellipse in canvas
canvas.add(ellipse);
</script>
</body>
</html>
输出: