- 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 an Ellipse using FabricJS?
In this tutorial, we are going to learn how to set the height of an Ellipse using FabricJS. Ellipse is one of the various shapes provided by FabricJS. In order to create an ellipse, we will create an instance of fabric.Ellipse class and add it to the canvas. We can manipulate an ellipse 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.Ellipse({ height: Number }: Object)
Parameters
options (optional) − This parameter is an Object which provides additional customizations to our ellipse. Using this parameter color, 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 take 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>How to set the height of an Ellipse using FabricJS?</h2> <p>Here we have set the dimensions of the ellipse by passing the horizonal and vertical radius, <b>rx</b> and <b>ry</b>. We have not used the <b>height</b> property. </p> <canvas id="canvas"></canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); // Initiate an ellipse instance var ellipse = new fabric.Ellipse({ left: 100, top: 100, fill: "white", rx: 100, ry: 60, stroke: "#c154c1", strokeWidth: 5, }); // Adding it to the canvas canvas.add(ellipse); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); </script> </body> </html>
Example 2
Passing height property as key
Since the dimensions of an ellipse are determined by its horizontal and vertical radius, there will not be any changes in its size.
<!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>How to set the height of an Ellipse using FabricJS?</h2> <p>There is no change in the dimensions of the ellipse even though we have used the <b>height</b> property. This is because the dimensions are controlled by the horizontal and vertical radius, <b>rx</b> and <b>ry</b>. </p> <canvas id="canvas"></canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); // Initiate an ellipse instance var ellipse = new fabric.Ellipse({ top: 100, left: 100, fill: "white", rx: 100, ry: 60, height: 90, stroke: "#c154c1", strokeWidth: 5, }); // Adding it to the canvas canvas.add(ellipse); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); </script> </body> </html>
- Related Articles
- How to set the opacity of an Ellipse using FabricJS?
- How to set the padding of an Ellipse using FabricJS?
- How to set the angle of rotation of an Ellipse using FabricJS?
- How to set the position of an Ellipse from left using FabricJS?
- How to set the scale factor (border) of an Ellipse using FabricJS?
- How to set the vertical scale factor of an Ellipse using FabricJS?
- How to set the horizontal and vertical radius of an Ellipse using FabricJS?
- How to set the minimum allowed scale value of an Ellipse using FabricJS?
- How to set the fill color of Ellipse using FabricJS?
- How to set the width of stroke of Ellipse using FabricJS?
- How to set the horizontal scale factor of Ellipse using FabricJS?
- How to set the background color of selection of Ellipse using FabricJS?
- 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 size of the controlling corners of Ellipse using FabricJS?
