FabricJS Articles

Page 12 of 51

How to straighten a rotated Polygon object using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 265 Views

We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. We can straighten a rotated Polygon object by using the straighten method. The straighten method straightens an object by rotating it from its current angle to the nearest cardinal angle (0°, 90°, 180°, or 270°), depending on which is closer. Syntax straighten(): ...

Read More

How to switch off object caching for a Polygon object using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 659 Views

We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity, etc. A FabricJS object is cached on an additional canvas for saving time during re-using the object. In order to switch off object caching for Polygon object we use the objectCaching property. Syntax new fabric.Polygon( points: Array, { objectCaching: Boolean }: Object ) ...

Read More

How to create a JSON representation of a Line object using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 546 Views

In this tutorial, we are going to learn about how to create a JSON representation of a Line object using FabricJS. A Line element is one of the basic elements provided in FabricJS. It is used for creating straight lines. Because line elements are geometrically one-dimensional and do not contain an interior, they are never filled. We can create a line object by creating an instance of fabric.Line, specifying the x and y coordinates of the line and adding it to the canvas. In order to create a JSON representation of a Line object, we use the toJSON method. ...

Read More

How to create a canvas using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 2K+ Views

In this article, we are going to create a canvas using FabricJS but before that let us understand what a canvas is. For drawing graphics on a webpage, we have a web API called Canvas API. This API is good for drawing basic shapes but adding interaction to it or drawing complex shapes becomes very difficult. Thus FabricJS comes into the picture which is a library built on top of the Canvas API. To use FabricJS, the first thing that needs to be done is to create a FabricJS Canvas. Syntax new fabric.Canvas(element: HTMLElement|String, options: Object) ...

Read More

How to create a canvas with a background color using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 1K+ Views

In this article, we are going to create a canvas with a given background color using FabricJS. The default background color provided by the FabricJS API is white and it can be customized using the backgroundColor option. Syntax new fabric.Canvas(element: HTMLElement|String, { backgroundColor: String }: Object) Parameters element − This parameter is the element itself which can be derived using document.getElementById() or the id of the element itself. The FabricJS canvas will be initialized on this element. ...

Read More

How to create a canvas with background image using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 7K+ Views

In this article, we are going to create a canvas with a background image using FabricJS. There are two ways available in FabricJS, using which we can change the background image of the canvas. First method is by using the Canvas class itself and passing backgroundImage in the second parameter of the class. Second method is to use the setBackgroundImage method. Let's see into each of them with an example. ...

Read More

How to create a canvas with a class using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 734 Views

In this article, we will see how to create a canvas with a class on it using the containerClass property. In order to have access over the native HTML canvas element, we can add a wrapper class over it. This class allows us to have control over the element to add interactivity or styling as per requirement. Syntax new fabric.Canvas(element: HTMLElement|String, { containerClass: String}: Object) Parameters element − This parameter is the element itself which can be derived using document.getElementById() or the ...

Read More

How to disable selection of objects via dragging in a canvas using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 3K+ Views

In this article, we are going to illustrate how you can disable the selection of objects via dragging in FabricJS. In a FabricJS canvas, we can basically click anywhere and select an area and any object in that area will get selected. In this article, we will see how to disallow this behavior. Syntax new fabric.Canvas(element: HTMLElement|String, {selection: boolean}: Object) Parameters element − This parameter is the element itself which can be derived using document.getElementById() or the id of the element ...

Read More

How to create a canvas with crosshair cursor on hover over objects using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 869 Views

In this article, we are going to create a canvas with a crosshair cursor on hover using FabricJS. The crosshair is one of the native cursor styles available which can be used in FabricJS canvas. FabricJS provides various cursor types like default, all-scroll, crosshair, col-resize, row-resize etc., which reuse native CSS cursors. The hoverCursor property sets the cursor style when hovering over canvas objects. Syntax new fabric.Canvas(element: HTMLElement|String, { hoverCursor: String }: Object) Parameters element − This parameter is the element itself ...

Read More

How to create a canvas with not-allowed cursor on hover over objects using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 448 Views

In this article, we are going to create a canvas with a not-allowed cursor on hover using FabricJS. The not-allowed cursor is one of the native cursor styles available which can be used in FabricJS canvas. FabricJS provides various types of cursors like default, all-scroll, crosshair, col-resize, row-resize, etc., that reuse the native cursor under the hood. The hoverCursor property sets the style of the cursor when hovered over a canvas object. Syntax new fabric.Canvas(element, { hoverCursor: "not-allowed" }) Parameters element − This ...

Read More
Showing 111–120 of 506 articles
« Prev 1 10 11 12 13 14 51 Next »
Advertisements