- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set the colour of controlling corners of Textbox using FabricJS?
In this tutorial, we are going to set the colour of the controlling corners of Textbox using FabricJS. We can customize, stretch or move around the text written in a textbox. We can also customize the text itself by using properties like fontSize, fontFamily, fontStyle, fontWeight etc. In order to create a textbox, we will have to create an instance of fabric.Textbox class and add it to the canvas. The cornerColor property allows us to manipulate the colour of the controlling corners when the object is active.
Syntax
new fabric.Textbox(text: String, { cornerColor: String }: Object)
Parameters
text − This parameter accepts a String which is the text string that we want to display inside our textbox.
options (optional) − This parameter is an Object which provides additional customizations to our textbox. Using this parameter, properties such as colour, cursor, stroke width and a lot of other properties can be changed related to the object of which the cornerColor is a property.
Options Keys
cornerColor: This property accepts a String which allows us to assign a color to the controlling corners when the object is actively selected. The default value is rgb(178,204,255).
Example 1
Passing cornerColor as key with a color name as value
Let’s see a code example to change the colour by using the cornerColor property. In this case we have assigned the value “orange” to the key which thus makes the controlling corners appear orange.
<!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 cornerColor as key with a color name as value</h2> <p>You can select the textbox to see that the corner colour is orange</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 little progress each day adds up to big results.", { backgroundColor: "#ffe5b4", width: 400, top: 70, left: 110, cornerColor: "orange", }); // Add it to the canvas canvas.add(textbox); </script> </body> </html>
Example 2
Assigning an RGBA value to the cornerColor property
Instead of passing a simple colour name as the String value to the key, we can also assign an RGBA value. RGBA stands for red, green, blue and alpha, where alpha is the opacity. Let us see a code example of how we can do that −
<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>Assigning an RGBA value to the cornerColor property</h2> <p>You can select the textbox to see the corner colour</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 little progress each day adds up to big results.", { backgroundColor: "#ffe5b4", width: 400, top: 70, left: 110, cornerColor: "rgba(255,69,0, 0.8)", }); // Add it to the canvas canvas.add(textbox); </script> </body> </html>
- Related Articles
- How to set the style of controlling corners of Textbox using FabricJS?
- How to set the size of the controlling corners of Textbox using FabricJS?
- How to set the dash pattern of controlling corners of Textbox using FabricJS?
- How to set the colour of controlling corners of a Triangle using FabricJS?
- How to set the colour of controlling corners of a Rectangle using FabricJS?
- How to set the colour of the controlling corners of a Circle using FabricJS?
- How to make the controlling corners of a Textbox transparent using FabricJS?
- FabricJS – How to set the colour of the controlling corners of a Line?
- FabricJS – How to set the stroke colour of the controlling corners of a Line?
- How to set the color of controlling corners of Ellipse using FabricJS?
- How to set the style of controlling corners of Ellipse using FabricJS?
- How to set the style of controlling corners of Text using FabricJS?
- How to set the size of the controlling corners of Ellipse using FabricJS?
- How to set the size of the controlling corners of Rectangle using FabricJS?
- How to set the size of the controlling corners of Text using FabricJS?
