如何在 FabricJS 編輯模式下設定文字物件的邊框顏色?
在本教程中,我們將學習如何在使用 FabricJS 的編輯模式下設定文字物件的邊框顏色。我們可以透過新增填充顏色、消除邊框甚至更改尺寸來自定義文字框物件。同樣,可以指示文字是否可編輯。我們還可以使用名為 editingBorderColor 的屬性更改文字物件在編輯模式下的邊框顏色。
語法
new fabric.Textbox(text: String, { editingBorderColor: String }: Object)
引數
text − 此引數接受一個字串,它是我們希望在文字框內顯示的文字字串。
options (可選) − 此引數是一個物件,它為我們的文字框提供額外的自定義。使用此引數,可以更改與物件相關的顏色、游標、邊框寬度以及許多其他屬性,其中editingBorderColor 是一個屬性。
選項鍵
editingBorderColor:此屬性接受一個字串,允許我們控制文字物件在編輯模式下的邊框顏色。editingBorderColor 屬性的預設值為rgba(102,153,255,0.25)。
示例 1
文字框物件的預設外觀
讓我們看一個程式碼示例,瞭解我們的文字框物件在editingBorderColor 屬性的預設值下是什麼樣子。在本例中,我們不會向類傳遞任何editingBorderColor 鍵,如下所示:
<!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>Default appearance of a textbox object</h2> <p>You can double click on the textbox to enable editing mode</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("Being positive is a sign of intelligence.", { left: 110, top: 45, fill: "black", stroke: "green", width: 400, backgroundColor: "#ffffe7", }); // Add it to the canvas canvas.add(textbox); </script> </body> </html>
示例 2
將editingBorderColor 屬性作為鍵傳遞
在本例中,我們將瞭解如何為editingBorderColor 屬性賦值會更改文字物件在編輯模式下邊框的顏色。這裡我們使用顏色“紅色”進行演示。
<!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 the editingBorderColor property as key</h2> <p>You can double click on the text object to see that in editing mode the colour of the border is red</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("Being positive is a sign of intelligence.", { left: 110, top: 45, fill: "black", stroke: "green", width: 400, backgroundColor: "#ffffe7", editingBorderColor: "red", }); // Add it to the canvas canvas.add(textbox); </script> </body> </html>
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP