简体   繁体   English

获取object中目标object的初始state:fabric.js中的修改事件

[英]Obtaining initial state of target object in object:modified event in fabric.js

I have a drawing application that uses fabric.js and I have implemented an undo/redo function based on the fabric-history repository on github.我有一个使用fabric.js 的绘图应用程序,并且基于github 上的fabric-history 存储库实现了撤消/重做function。 However, because this approach saves entire canvas states in a stack, the browser quickly becomes non-responsive as it deals with all this data.但是,由于这种方法将整个 canvas 状态保存在堆栈中,因此浏览器在处理所有这些数据时很快变得无响应。 I would like an undo/redo method that only saves the object that is changed in an interaction with an object on the canvas and not the whole canvas.我想要一个撤消/重做方法,它只保存在与 canvas 上的 object 交互时更改的 object 而不是整个 object,而不是整个 object Using the object:modified event, I see I can get the target object of the event after it is modified, but I also need the object target state before the modification was made to restore it in an undo. Using the object:modified event, I see I can get the target object of the event after it is modified, but I also need the object target state before the modification was made to restore it in an undo. Any suggestions on how to obtain this state of an object would be appreciated.任何有关如何获得 object 的 state 的建议将不胜感激。

I think you can use the saveState method for it.我认为您可以使用saveState方法。 After calling this method object gets _stateProperty object that contains current values of left, top, and other properties.调用此方法后,object 获得_stateProperty object,其中包含 left、top 和其他属性的当前值。 You can read more about saveState method in doc您可以在doc中阅读有关saveState方法的更多信息

I've made a simple example to demonstrate this approach here我在这里做了一个简单的例子来演示这种方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM