首頁  >  文章  >  web前端  >  如何使用 FabricJS 鎖定圓的垂直傾斜?

如何使用 FabricJS 鎖定圓的垂直傾斜?

WBOY
WBOY轉載
2023-08-30 12:09:041338瀏覽

如何使用 FabricJS 锁定圆的垂直倾斜?

在本教程中,我們將學習如何使用 FabricJS 鎖定圓的垂直傾斜。正如我們可以指定畫布中圓形物件的位置、顏色、不透明度和尺寸一樣,我們也可以指定是否要停止垂直傾斜物件。這可以透過使用lockSkewingY屬性來完成。

語法

new fabric.Circle({ lockSkewingY : Boolean }: Object)

參數

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

  • ul>

    選項鍵

    • #lockSkewingY - 此屬性接受布林值 值。如果我們為其指定“true”值,則物件的垂直傾斜將被鎖定。

    範例1

    a 的預設行為畫布中的Circle 物件

    讓我們看一個程式碼範例,以了解不使用lockSkewingY 屬性時Circle 物件的預設行為。按下 shift 鍵,然後沿著水平或垂直方向拖曳,可以使物件在水平和垂直方向上傾斜。

    <!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>Locking the vertical skewing of a circle using FabricJS</h2>
          <p>Select the object, hold the <b>shift</b> key, and stretch it horizontally or vertically. The object will get skewed freely. This is the default behavior. Here we have not applied the <b>lockSkewingY</b> property, but by default, it is set to False. </p>
          <canvas id="canvas"></canvas>
    
          <script>
             // Initiate a canvas instance
             var canvas = new fabric.Canvas("canvas");
             var circle = new fabric.Circle({
                left: 115,
                top: 50,
                fill: "white",
                radius: 50,
                stroke: "black",
                strokeWidth: 5
             });
    
             // Adding it to the canvas
             canvas.add(circle);
             canvas.setWidth(document.body.scrollWidth);
             canvas.setHeight(250);
          </script>
       </body>
    </html>

    範例2

    將lockSkewingY 作為具有「true」值的鍵傳遞

    在這個範例中,我們將看到如何停止圓的能力使用lockSkewingY 屬性垂直傾斜物件。正如我們所看到的,雖然我們可以透過按 Shift 鍵來水平傾斜圓形對象,但我們不允許垂直執行相同的操作。

    <!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>Locking the vertical skewing of a circle using FabricJS</h2>
          <p>Select the object, hold the <b>shift</b> key, and try to stretch the circle horizontally or vertically. You will notice that the object gets skewed horizontally, but its vertical skewing is locked. Here we have set <b>lockSkewingY</b> to True. </p>
          <canvas id="canvas"></canvas>
    
          <script>
             // Initiate a canvas instance
             var canvas = new fabric.Canvas("canvas");
             var circle = new fabric.Circle({
                left: 115,
                top: 50,
                fill: "white",
                radius: 50,
                stroke: "black",
                strokeWidth: 5,
                lockSkewingY: true
             });
       
             // Adding it to the canvas
             canvas.add(circle);
             canvas.setWidth(document.body.scrollWidth);
             canvas.setHeight(250);
          </script>
       </body>
    </html>

以上是如何使用 FabricJS 鎖定圓的垂直傾斜?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除