Fabric.js 椭圆 hasRotatingPoint 属性
在本文中,我们将看到如何使用FabricJS禁用画布椭圆的旋转点。画布意味着椭圆可移动并且可以根据需求拉伸。此外,当涉及到初始描边颜色、填充颜色、描边宽度或半径时,可以自定义椭圆。
方法: 为了实现这一点,我们将使用一个名为FabricJS的JavaScript库。在使用CDN导入库之后,我们将在body标签中创建一个包含椭圆的canvas块。然后,我们将使用FabricJS提供的Canvas和Ellipse的实例,并使用 hasRotatingPoint 属性禁用画布椭圆的旋转点,如下面的示例所示。
语法:
fabric.Ellipse({
rx: number,
ry: number,
hasRotatingPoint: boolean
});
参数: 此函数接受如上所述的三个参数,并进行如下描述:
- rx: 它指定了水平半径。
- ry: 它指定了垂直半径。
- hasRotatingPoint: 它指定是否显示旋转点。
程序: 下面的示例使用FabricJS来禁用类似画布的椭圆形的旋转点。请注意,您必须点击对象才能看到旋转点。
<!DOCTYPE html>
<html>
<head>
<title>
Fabric.js Ellipse hasRotatingPoint Property
</title>
<!-- Loading the FabricJS library -->
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js">
</script>
</head>
<body>
<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 Ellipse instance
var ellipse = new fabric.Ellipse({
rx: 80,
ry: 40,
hasRotatingPoint: false
});
// Render the Ellipse in canvas
canvas.add(ellipse);
</script>
</body>
</html>
输出: