- 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 create a Circle with wait cursor on hover over objects using FabricJS?
In this tutorial, we are going to create a Circle with a wait cursor on hover over objects using FabricJS. wait is one of the native cursor styles available which can be used in the FabricJS canvas too. FabricJS provides various types of cursors like default, all-scroll, crosshair, col-resize, row-resize, etc., which are reusing the native cursor underhood. The hoverCursor property sets the style of the cursor when hovered over a canvas object.
Syntax
new fabric.Circle({ hoverCursor: String }: 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 hoverCursor is a property.
Options Keys
hoverCursor − This property accepts a String which determines the name of the cursor to be used on hovering over the canvas object. By using this property, we can set the default cursor value when hovering over the circle object on the canvas.
Example 1
Passing the hoverCursor Key to the class
By default, when we hover over a circle object in the canvas, the cursor type is move. Let's see a code example to create a canvas with a wait cursor while hovering over a circle object in FabricJS.
<!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>Creating a circle with wait cursor on hover over objects using FabricJS</h2> <p>Hover the mouse over the object to see changed shape of the cursor. Here we have used the <b>hoverCursor</b> property to show a <b>wait</b> cursor on hover. </p> <canvas id="canvas"></canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); var circle = new fabric.Circle({ left: 115, top: 100, fill: "#87ceeb", radius: 50, stroke: "#ace5ee", strokeWidth: 5, hoverCursor: "wait" }); // Adding it to the canvas canvas.add(circle); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); </script> </body> </html>
Example 2
Demonstrating that this affects the instance only
In this example, we are passing the hoverCursor key to the circle class which means that the hoverCursor property would not be changed for every object in the canvas. Changes will only occur for that single object. This is illustrated in the example below:
<!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>Creating a circle with wait cursor on hover over objects using FabricJS</h2> <p>Move the cursor over the objects. You will get to see the <b>wait</b> cursor when you hover the mouse over the left circle. We have not applied the <b>hoverCursor</b> property on the right circle which shows the default <b>move</b> cursor on hover. </p> <canvas id="canvas"></canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); var circle = new fabric.Circle({ left: 115, top: 100, fill: "#87ceeb", radius: 50, stroke: "#ace5ee", strokeWidth: 5, hoverCursor: "wait" }); var circle2 = new fabric.Circle({ left: 335, top: 100, fill: "#ffe4e1", radius: 50, stroke: "#ace5ee", strokeWidth: 5, }); // Adding it to the canvas canvas.add(circle); canvas.add(circle2); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); </script> </body> </html>
- Related Articles
- How to create a Rectangle with wait cursor on hover over objects using FabricJS?
- How to create a canvas with wait cursor on hover over objects using FabricJS?
- How to create an Ellipse with wait cursor on hover over objects using FabricJS?
- How to create a Circle with crosshair cursor on hover over objects using FabricJS?
- How to create a Circle with help cursor on hover over objects using FabricJS?
- How to create a Circle with progress cursor on hover over objects using FabricJS?
- How to create a Circle with text cursor on hover over objects using FabricJS?
- How to create a Circle with not-allowed cursor on hover over objects using FabricJS?
- How to create a Rectangle with crosshair cursor on hover over objects using FabricJS?
- How to create a Rectangle with help cursor on hover over objects using FabricJS?
- How to create a Rectangle with progress cursor on hover over objects using FabricJS?
- How to create a Rectangle with text cursor on hover over objects using FabricJS?
- How to create a canvas with crosshair cursor on hover over objects using FabricJS?
- How to create a canvas with help cursor on hover over objects using FabricJS?
- How to create a canvas with progress cursor on hover over objects using FabricJS?
