首頁 > web前端 > js教程 > 主體

如何使用 FabricJS 隱藏橢圓的控制邊框?

王林
發布: 2023-08-24 15:17:04
轉載
683 人瀏覽過

如何使用 FabricJS 隐藏椭圆的控制边框?

在本教學中,我們將學習如何使用 FabricJS 隱藏橢圓的控制邊框。橢圓形是 FabricJS 提供的各種形狀之一。為了創建一個橢圓,我們必須建立一個 Fabric.Ellipse 類別的實例並將其新增到畫布中。我們可以透過多種方式自訂控制邊框,例如添加特定顏色、破折號圖案等。但是,我們也可以使用 hasBorders 屬性來完全消除邊框。

語法

new fabric.Ellipse({ hasBorders: Boolean }: Object)
登入後複製

參數

  • #選項(可選)- 此參數是一個物件< /em> 為我們的橢圓提供額外的客製化。使用此參數,可以變更與 hasBorders 為屬性的物件相關的顏色、遊標、描邊寬度和許多其他屬性。

選項鍵

  • #hasBorders - 此屬性接受布爾值當設定為False時,控制邊框將不會被渲染。預設值為True

範例1

橢圓物件控制邊框的預設外觀< /strong>

##以下範例顯示了橢圓形控制邊框的預設外觀。由於

hasBorders 屬性的預設值為“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>How to hide the controlling borders of an Ellipse using FabricJS?</h2>
      <p>Select the object and you would get to see the controlling borders. This is the default behavior.</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: 105,
            top: 100,
            fill: "white",
            rx: 100,
            ry: 60,
            stroke: "#c154c1",
            strokeWidth: 5,
         });

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

範例2

hasBorders 作為鍵傳遞並為其指派「false」值

如果

>hasBorders 屬性被賦予「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 hide the controlling borders of an Ellipse using FabricJS?</h2>
      <p>Select the object. Now you won&#39;t get to see the controlling borders because we have set the <b>hasBorders</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: 105,
            top: 100,
            fill: "white",
            rx: 100,
            ry: 60,
            stroke: "#c154c1",
            strokeWidth: 5,
            hasBorders: false,
         });

         // 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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!