- 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 height of a Circle using FabricJS?
In this tutorial, we are going to learn how to set the height of a Circle using FabricJS. Circle is one of the various shapes provided by FabricJS. In order to create a circle, we have to create an instance of fabric.Circle class and add it to the canvas. We can manipulate a circle object by changing its position, opacity, stroke and also its dimension. FabricJS allows us to control an object's dimensions by using the width and height properties.
Syntax
new fabric.Circle({ height: Number }: Object)
Parameters
options (optional) − This parameter is an Object which provides additional customizations to our circle. 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 height is a property.
Options Keys
height − This property accepts a Number allows us to specify the object's height. The value that is assigned, determines the height.
Example 1
Default behaviour of height property
Let's see an example to understand the default behaviour of the height property.
<!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>Setting the height of a Circle using FabricJS</h2> <p>Note that the dimensions of the circle are controlled by its radius. Select the object and observe the height of its controlling borders. Here we have not used the <b>height</b> property and this is the default appearnace. </p> <canvas id="canvas"></canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); var circle = new fabric.Circle({ left: 215, top: 100, fill: "white", radius: 50, stroke: "#c154c1", strokeWidth: 5, }); // Adding it to the canvas canvas.add(circle); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); </script> </body> </html>
Example 2
Passing height property as key
Since the dimensions of a circle are determined by its radius, there will not be any changes in its size. However, as we can see, the height of the controlling borders has changed after assigning the height property a value.
<!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>Setting the height of a Circle using FabricJS</h2> <p>Select the object and notice the height of its controlling borders. Here we have set the <b>height</b> to 150px. </p> <canvas id="canvas"></canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); var circle = new fabric.Circle({ left: 215, top: 100, fill: "white", radius: 50, stroke: "#c154c1", strokeWidth: 5, height: 150 }); // Adding it to the canvas canvas.add(circle); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); </script> </body> </html>
- Related Articles
- How to set the opacity of a Circle using FabricJS?
- How to set the padding of a Circle using FabricJS?
- How to set the radius of a Circle using FabricJS?
- How to set the height of a Triangle using FabricJS?
- How to set the fill color of a Circle using FabricJS?
- How to set the angle of rotation of a Circle using FabricJS?
- How to set the height of an Ellipse using FabricJS?
- How to set the horizontal scale factor of a Circle using FabricJS?
- How to set the position of a Circle from left using FabricJS?
- How to set the scale factor (border) of a Circle using FabricJS?
- How to set the width of stroke of Circle using FabricJS?
- How to set the style of controlling corners of a Circle using FabricJS?
- How to set the vertical scale factor of Circle using FabricJS?
- How to set the colour of the controlling corners of a Circle using FabricJS?
- How to set the size of the controlling corners of a Circle using FabricJS?
