I'm trying to accomplish undo/redo. I'm using loadFromJSON(...) to re-build the canvas from the canvas states I've stored in an array. Basically, my idea is to destroy the existing canvas and re-construct canvas. Here is my code.
// TODO: How to destroy existing canvas?
canvas = new fabric.Canvas('canvas', {
containerClass : 'myCanvasContainer',
});
canvas.loadFromJSON(history[historyStep]);
This code adds another canvas on top of existing canvas. However, I need a way to destroy the canvas and to build brand new canvas from my JSON data (replacing old canvas with new one).
Please advise whether it's possible or any other options I have.
I believe canvas.dispose()
is what you are looking for.
Read more here: http://fabricjs.com/docs/fabric.StaticCanvas.html#dispose
You can use the canvas.clear() function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With