在本教程中,我們將學(xué)習(xí)如何使用 FabricJS 鎖定橢圓的水平傾斜。正如我們可以指定畫布中橢圓對(duì)象的位置、顏色、不透明度和尺寸一樣,我們也可以指定是否要停止水平傾斜對(duì)象。這可以通過使用lockSkewingX屬性來完成。
語法
new fabric.Ellipse({ lockSkewingX : Boolean }: Object)
登錄后復(fù)制
參數(shù)
選項(xiàng)(可選)- 此參數(shù)是一個(gè)提供額外自定義的對(duì)象到我們的橢圓。使用此參數(shù),可以更改與 lockSkewingX 為屬性的對(duì)象相關(guān)的顏色、光標(biāo)、描邊寬度和許多其他屬性。
選項(xiàng)鍵
lockSkewingX – 此屬性接受布爾值值。如果我們?yōu)槠渲付ā皌rue”值,則對(duì)象的水平傾斜將被鎖定。
示例 1
默認(rèn)行為畫布中的 Ellipse 對(duì)象
讓我們通過一個(gè)示例來了解未使用 lockSkewingX 屬性時(shí) Ellipse 對(duì)象的默認(rèn)行為。通過按住 Shift 鍵,然后沿水平或垂直方向拖動(dòng),可以使對(duì)象在水平和垂直方向上傾斜。
<!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 horizontal skewing of Ellipse using FabricJS</h2> <p>Select the object. Hold the "shift" and try to stretch the object (not diagonally). You can skew the object both horizontally and vertically. 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: 115, top: 50, fill: "white", rx: 80, ry: 50, stroke: "black", strokeWidth: 5, }); // Adding it to the canvas canvas.add(ellipse); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); </script> </body> </html>
登錄后復(fù)制
示例 2
將 lockSkewingX 作為具有“true”值的鍵傳遞
在此示例中,我們將了解如何可以使用lockSkewingX屬性來停止Ellipse對(duì)象水平傾斜的能力。雖然我們可以垂直傾斜橢圓對(duì)象,但我們不允許水平執(zhí)行相同的操作。
<!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 lock the horizontal skewing of Ellipse using FabricJS?</h2> <p>Select the object; hold the "shift" key and try to stretch the object horizontally. You cannot skew the object horizontally because we have set <b>lockSkewingX</b> to True. </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, fill: "white", rx: 80, ry: 50, stroke: "black", strokeWidth: 5, lockSkewingX: true, }); // Adding it to the canvas canvas.add(ellipse); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); </script> </body> </html>
登錄后復(fù)制
以上就是如何使用 FabricJS 鎖定 Ellipse 的水平傾斜?的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注www.92cms.cn其它相關(guān)文章!