如何使用 FabricJS 設定文字框 Y 軸的傾斜角度?
在本教程中,我們將學習如何使用 FabricJS 設定文字框 Y 軸的傾斜角度。我們可以自定義、拉伸或移動文字框中編寫的文字。為了建立文字框,我們必須建立一個 fabric.Textbox 類的例項並將其新增到畫布上。我們的文字框物件可以透過多種方式進行自定義,例如更改其尺寸、新增背景顏色或更改 Y 軸的傾斜角度。我們可以透過使用 skewY 屬性來實現這一點。
語法
new fabric.Textbox(text: String, { skewY : Number }: Object)
引數
text − 此引數接受一個字串,它是我們希望在文字框內顯示的文字字串。
options (可選) − 此引數是一個物件,它為我們的文字框提供了額外的自定義選項。使用此引數,可以更改與物件相關的許多屬性,例如顏色、游標、描邊寬度等等,其中skewY也是一個屬性。
選項鍵
skewY − 此屬性接受一個數字,它決定了物件在 Y 軸上的傾斜角度。
示例 1
當未應用 skewY 屬性時
讓我們看一個程式碼示例,瞭解當未應用 skewY 屬性時我們的文字框物件的外觀。在這種情況下,我們的文字框物件將不會以任何角度傾斜。
<!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>When the skewY property is not applied</h2> <p>You can see there is no skew by any angle on the textbox by default</p> <canvas id="canvas"></canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); // Initiate a textbox object var textbox = new fabric.Textbox("A smile cures the wounding of a frown.", { backgroundColor: "#fffff0", width: 400, left: 110, top: 70, fill: "violet", strokeWidth: 2, stroke: "blue", textAlign: "center", }); // Add it to the canvas canvas.add(textbox); </script> </body> </html>
示例 2
將 skewY 作為鍵併為其分配自定義值。
在此示例中,我們將瞭解如何為 skewY 屬性分配數值。傳遞的值將決定沿 Y 軸的傾斜。
<!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>Passing skewY as key and assigning a custom value to it.</h2> <p>You can see the textbox has been skewed along the y-axis</p> <canvas id="canvas"></canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); // Initiate a textbox object var textbox = new fabric.Textbox("A smile cures the wounding of a frown.", { backgroundColor: "#fffff0", width: 400, left: 110, top: 70, fill: "violet", strokeWidth: 2, stroke: "blue", textAlign: "center", skewY: 30, }); // Add it to the canvas canvas.add(textbox); </script> </body> </html>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP