Do we have canvas Modified Event in Fabric.js?

2019-02-13 10:55发布

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?

2条回答
叼着烟拽天下
2楼-- · 2019-02-13 11:38

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);
查看更多
Fickle 薄情
3楼-- · 2019-02-13 11:43

This is better explained in this link. Use it this way:

canvas.on('object:moving', function(e) { // or 'object:added'
  var activeObject = e.target;
  console.log(activeObject.get('left'), activeObject.get('top'));
});
查看更多
登录 后发表回答