Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do we have canvas Modified Event in Fabric.js?

In Fabric.js we have Object modified events like object:modified. Do we have similar event for the entire canvas.

Actually I am trying to implement undo and redo features. I am saving the canvas as JSON if something happens on it and loading it again for undo feature.

Do we have any better solution for this features in Fabric.js?

like image 696
user2571818 Avatar asked Aug 29 '13 09:08

user2571818


People also ask

How does fabric js work?

With native methods, you operate on context—an object representing the entire canvas bitmap. In Fabric, you operate on objects—you instantiate them, change their properties, and add them to the canvas. You can see that these objects are first-class citizens in Fabric land. Rendering a plain red rectangle is too simple.

Why do we use fabric js?

With the help of Fabric. js, every shape drawn on the canvas is a JavaScript object with properties and methods. Using these properties and methods we can manipulate the shape on the canvas without having to redraw the objects on the canvas manually.

Is fabric js open source?

js is a Javascript HTML5 canvas library. It is a fully open-source project with many contributions over the years.


1 Answers

Don't forget to check for added/removed objects too. You could implement it like this:

var canvasModifiedCallback = function() {
console.log('canvas modified!');
};

canvas.on('object:added', canvasModifiedCallback);
canvas.on('object:removed', canvasModifiedCallback);
canvas.on('object:modified', canvasModifiedCallback);
like image 128
Tomh Avatar answered Sep 21 '22 23:09

Tomh