首頁  >  文章  >  web前端  >  如何使用 FabricJS 使橢圓的控制角透明化?

如何使用 FabricJS 使橢圓的控制角透明化?

WBOY
WBOY轉載
2023-08-24 18:33:02545瀏覽

如何使用 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刪除