首页  >  文章  >  web前端  >  如何使用 FabricJS 使椭圆的控制角透明?

如何使用 FabricJS 使椭圆的控制角透明?

WBOY
WBOY转载
2023-08-24 18:33:02544浏览

如何使用 FabricJS 使椭圆的控制角透明?

在本教程中,我们将学习如何使用 FabricJS 使 Ellipse 的控制角透明。椭圆形是 FabricJS 提供的各种形状之一。为了创建一个椭圆,我们将创建一个 Fabric.Ellipse 类的实例并将其添加到画布中。 transparentCorners 属性允许我们使椭圆的控制角透明。

语法

new fabric.Ellipse( { transparentCorners: Boolean }: Object)

参数

  • 选项(可选)- 此参数是一个对象 为我们的椭圆提供额外的定制。使用此参数,可以更改与 transparentCorners 为属性的对象相关的颜色、光标、描边宽度和许多其他属性。

Options Keys

  • transparentCorners - 此属性接受布尔值这允许我们将对象的控制角渲染为透明。其默认值为 True

示例 1

传递 transparentCorners 属性作为具有“false”值的键

让我们看一下创建椭圆对象的代码,该椭圆对象具有不透明的控制角。为了实现这一点,我们需要向 transparentCorners 属性传递一个“false”值。

<!DOCTYPE html>
<html>
   <head>
      <!-- Adding the Fabric JS Library-->
      <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script>
   </head>

   <body>
      <h2>How to make controlling corners of Ellipse transparent using FabricJS?</h2>
      <p>Select the object and you will notice that the controlling corners are not transparent. Here we have set the <b>transparentCorners</b> property to False. </p>
      <canvas id="canvas"></canvas>
     
      <script>
         // Initiate a canvas instance
         var canvas = new fabric.Canvas("canvas");

         // Initiate an ellipse instance
         var ellipse = new fabric.Ellipse({
            left: 115,
            top: 50,
            rx: 100,
            ry: 70,
            fill: "red",
            transparentCorners: false,
         });

         // Adding it to the canvas
         canvas.add(ellipse);
         canvas.setWidth(document.body.scrollWidth);
         canvas.setHeight(250);
      </script>
   </body>
</html>

示例 2

transparentCorners 作为具有“true”值的键传递

在此示例中,我们将传递transparentCorners 属性为“true”值。这将确保控制角呈现为透明。请注意,这也是默认行为。

<!DOCTYPE html>
<html>
   <head>
      <!-- Adding the Fabric JS Library-->
      <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script>
   </head>

   <body>
      <h2>Making the controlling corners of an Ellipse transparent using FabricJS</h2>
      <p>Select the object and you will notice that its controlling coners are now transparent as we have applied the <b>transparentCorners</b> property. </p>
      <canvas id="canvas"></canvas>

      <script>
         // Initiate a canvas instance
         var canvas = new fabric.Canvas("canvas");

         // Initiate an ellipse instance
         var ellipse = new fabric.Ellipse({
            left: 115,
            top: 50,
            rx: 100,
            ry: 70,
            fill: "red",
            transparentCorners: true,
         });
     
         // Adding it to the canvas
         canvas.add(ellipse);
         canvas.setWidth(document.body.scrollWidth);
         canvas.setHeight(250);
      </script>
   </body>
</html>

以上是如何使用 FabricJS 使椭圆的控制角透明?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除