Do we have canvas Modified Event in Fabric.js?

99封情书 提交于 2019-12-19 02:55:24

问题


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?


回答1:


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'));
});



回答2:


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);


来源:https://stackoverflow.com/questions/18507291/do-we-have-canvas-modified-event-in-fabric-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!