- 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
FabricJS β How to set the size of the controlling corners of a Line?
In this tutorial, we are going to learn how to set the size of the controlling corners of Line using FabricJS. The controlling corners of an object allow us to scale, stretch or change its position. We can customize our controlling corners in many ways such as adding a specific colour to it, changing its size etc. We can change the size by using the cornerSize property.
Syntax
new fabric.Line( points: Array, { cornerSize: Number }: Object)
Parameters
points β This parameter accepts an Array of points which determines the (x1, y1) and (x2, y2) values, those being the x- and y-axis coordinates of the start and end of the line respectively.
options (optional) β This parameter is an Object which provides additional customizations to our object. Using this parameter origin, stroke width and a lot of other properties can be changed related to the object of which cornerSize is a property.
Options Keys
cornerSize β This property accepts a Number which allows us to manipulate the size of the controlling corners of a selected object. Its default value is 13.
Default size of the controlling corners
Example
Letβs see a code example that depicts the default size of the controlling corners of a line object when it is actively selected.
<!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 size of the controlling corners</h2> <p>You can select the line object to see the default size of controlling corners</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 Line object var line = new fabric.Line([200, 100, 100, 40], { stroke: "blue", strokeWidth: 20, }); // Add it to the canvas canvas.add(line); </script> </body> </html>
Passing cornerSize as key with a custom value
Example
In this example, we are passing the cornerSize property as key with a value of 17. We can see how that changes the size of our controlling corners when the line object is selected.
<!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 cornerSize as key with a custom value</h2> <p>You can select the line object to see the size of controlling corners</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 Line object var line = new fabric.Line([200, 100, 100, 40], { stroke: "blue", strokeWidth: 20, cornerColor: "#87a96b", cornerSize: 17, }); // Add it to the canvas canvas.add(line); </script> </body> </html>
- Related Articles
- FabricJS β How to set the colour of the controlling corners of a Line?
- How to set the size of the controlling corners of a Circle using FabricJS?
- How to set the size of the controlling corners of a Triangle 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?
- How to set the size of the controlling corners of Textbox using FabricJS?
- FabricJS β How to set the dash pattern 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 style of controlling corners of a Circle 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 style of controlling corners of a Triangle using FabricJS?
- How to set the style of controlling corners of a Rectangle using FabricJS?
- How to set the color of controlling corners of Ellipse using FabricJS?
