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

如何使用FabricJS設定橢圓選區的背景顏色?

PHPz
發布: 2023-09-10 13:13:02
轉載
1425 人瀏覽過

如何使用FabricJS設定橢圓選區的背景顏色?

在本教學中,我們將學習如何使用 FabricJS 設定橢圓選取範圍的背景顏色。橢圓形是 FabricJS 提供的各種形狀之一。為了創建一個橢圓,我們必須建立一個 Fabric.Ellipse 類別的實例並將其新增到畫布中。當主動選擇物件時,我們可以更改物件的尺寸、旋轉它或操縱它。我們可以使用 selectionBackgroundColor 屬性來變更橢圓選取範圍的背景顏色。

語法

new fabric.Ellipse({ selectionBackgroundColor : String }: Object)
登入後複製

參數

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

選項鍵

  • #selectionBackgroundColor## - 此屬性接受字符字串 決定選取範圍的背景顏色。

範例1

selectionBackgroundColor 屬性未使用< 时的默认颜色/em>

讓我們舉例來了解當

selectionBackgroundColor 屬性未使用時選擇內容的顯示方式。從這個例子我們可以看到,選擇區域或物件後面的區域沒有顏色。

<!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 set the background color of selection of Ellipse using FabricJS?</h2>
      <p>Select the object and you will observe that the selection background has no color. Here we have not applied the <b>selectionBackgroundColor</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: 80,
            ry: 50,
            fill: "#ff1493",
         });

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

範例2

selectionBackgroundColor 屬性作為鍵傳遞##在此範例中,我們將一個值指派給

selectionBackgroundColor

屬性。在本例中,我們將“darkBlue”顏色傳遞給它,因此選擇區域看起來是深藍色的。 < em>

<!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 set the background color of selection of Ellipse using FabricJS?</h2>
      <p>Select the object and you will observe that the background of the selection appears dark blue. This is because we have set the <b>selectionBackgroundColor</b> as dark blue. </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: 80,
            ry: 50,
            fill: "#ff1493",
            selectionBackgroundColor: "darkBlue",
         });

         // 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學習者快速成長!