- 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 border opacity of Textbox while moving using FabricJS?
In this tutorial, we are going to set the border opacity of a Textbox while moving using FabricJS. We can customize, stretch or move around the text written in a textbox. In order to create a textbox, we will have to create an instance of fabric.Textbox class and add it to the canvas. We can change the opacity of the border of a textbox while moving it around in the canvas by using the borderOpacityWhenMoving property.
Syntax
new fabric.Textbox(text: String, { borderOpacityWhenMoving: Number }: 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 borderOpacityWhenMoving is a property.
Options Keys
borderOpacityWhenMoving − This property accepts a Number that specifies how opaque we want the borders to be while moving the textbox around. It allows us to control the opacity of the borders while moving a textbox object. The default value is 0.4.
Example 1
Displaying the default behaviour of borderOpacityWhenMoving property
Let’s see a code example that shows the default behaviour of boderOpacityWhenMoving property. When we select our textbox object and move it around the canvas, the selection border changes its opacity from 1 (fully opaque) to 0.4 which makes it look a bit translucent.
<!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>Displaying the default behaviour of borderOpacityWhenMoving property</h2> <p>You can select the textbox and drag it around to see that the border opacity changes from being fully opaque (1) to being translucent (0.4)</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("Small steps motivate. Big steps overwhelm.", { backgroundColor: "#ffe5b4", width: 400, top: 70, left: 110, borderColor: "red", }); // Add it to the canvas canvas.add(textbox); </script> </body> </html>
Example 2
Passing borderOpacityWhenMoving as key
Let’s see a code example to assign a value to the borderOpacityWhenMoving property. In this case we have assigned the value as 0. This tells us that when we move our textbox around, the border opacity will change to 0 and will not be visible.
<!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 borderOpacityWhenMoving as key</h2> <p>You can select the textbox and drag it around to see that the borders are no longer visible when being moved</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("Small steps motivate. Big steps overwhelm.", { backgroundColor: "#ffe5b4", width: 400, top: 70, left: 110, borderColor: "red", borderOpacityWhenMoving: 0, }); // Add it to the canvas canvas.add(textbox); </script> </body> </html>
- Related Articles
- How to set the border opacity of Rectangle while moving using FabricJS?
- How to set the border opacity of a Circle while moving using FabricJS?
- How to set the border opacity of a Triangle while moving using FabricJS?
- FabricJS – How to set the border opacity of a Line while moving it?
- How to set the opacity of Textbox using FabricJS?
- How to set the border scale factor of Textbox using FabricJS?
- How to set the opacity of Triangle using FabricJS?
- How to set the opacity of Image using FabricJS?
- How to set the padding of Textbox using FabricJS?
- How to set the width of Textbox using FabricJS?
- How to set the opacity of an Ellipse using FabricJS?
- How to set the opacity of a Circle using FabricJS?
- How to set the opacity of a Rectangle using FabricJS?
- How to set the edit mode of Textbox using FabricJS?
- How to create a Textbox with border colour using FabricJS?
