Fabric.js Rect hasRotatingPoint属性
在本文中,我们将看到如何使用 FabricJS 设置画布矩形的旋转点。画布矩形意味着矩形可移动并可根据需要拉伸。此外,矩形在初始描边颜色、高度、宽度、填充颜色或描边宽度方面可以进行自定义。
为了实现这一点,我们将使用一个名为 FabricJS 的 JavaScript 库。在导入库之后,我们将在 body 标签中创建一个包含矩形的画布块。在此之后,我们将使用 FabricJS 提供的 Canvas 和 Rect 实例来设置画布矩形的旋转点,使用 hasRotatingPoint 属性,并在 Canvas 上渲染椭圆,如下面的示例中所示。
语法:
fabric.Rect({
width: number,
height: number,
hasRotatingPoint: Boolean
});
参数: 此函数接受三个参数,如上所述并描述如下:
- width: 它指定矩形的宽度。
- height: 它指定矩形的高度。
- hasRotatingPoint: 它指定是否显示旋转点。
示例: 此示例使用FabricJS来水平翻转画布矩形。
<!DOCTYPE html>
<html>
<head>
<title>
Fabric.js Rect hasRotatingPoint Property
</title>
<!-- Adding the FabricJS library -->
<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 Rect hasRotatingPoint Property
</b>
</div>
<canvas id="canvas" width="600" height="200"
style="border:1px solid #000000">
</canvas>
<script>
// Initiate a Canvas instance
var canvas = new fabric.Canvas("canvas");
// Initiate a Rect instance
var rectangle = new fabric.Rect({
width: 200,
height: 100,
fill: '',
stroke: 'green',
strokeWidth: 3,
hasRotatingPoint: false
});
// Render the Rect in canvas
canvas.add(rectangle);
canvas.centerObject(rectangle);
</script>
</body>
</html>
输出: