Fabric.js 圆 hasRotatingPoint属性

Fabric.js 圆 hasRotatingPoint属性

在本文中,我们将看到如何使用FabricJS禁用画布圆的旋转。画布意味着圆可移动,并且可以根据需求进行拉伸。此外,当涉及到初始描边颜色、填充颜色、描边宽度或半径时,可以自定义圆。

方法: 为了实现这一点,我们将使用一个称为FabricJS的JavaScript库。通过使用CDN导入库之后,在标签中创建一个canvas块,其中包含我们的圆。在此之后,我们将使用FabricJS提供的Canvas和Circle实例初始化并禁用圆的旋转,使用 hasRotatingPoint 属性,并按照以下示例将Circle渲染到Canvas上。

语法:

fabric.Circle({
    radius: number,
    hasRotatingPoint: boolean
}); 

参数: 该函数接受两个参数,如上所述并如下所述:

  • radius: 它指定圆的半径。
  • hasRotatingPoint: 它指定是否禁用旋转控件。

示例: 此示例使用FabricJS来禁用画布圆的旋转。注意,您必须点击对象以查看角落。

<!DOCTYPE html> 
<html> 
  
<head> 
    <title>  
        Fabric.js hasRotatingPoint Property 
    </title> 
  
    <!-- FabricJS CDN -->
    <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 Circle instance 
        var circle = new fabric.Circle({ 
            radius: 50, 
            hasRotatingPoint: false 
        }); 
  
        // Render the circle in canvas 
        canvas.add(circle); 
    </script> 
</body> 
  
</html> 

输出:

Fabric.js 圆 hasRotatingPoint属性

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程