简体   繁体   中英

Undo and redo on drawing board with Fabric.js and Fabric-brush.js

I developed a drawing board with Fabric.js and Fabric-brush.js. While when I add undo and redo functions, they doesn't work. But they can work when I don't refer fabric-brush.js. So how can I make the Spray Brush function with fabric-brush.js and Undo and Redo function together?

Here is its Jsfiddle link: https://jsfiddle.net/Miamiaoke/x68v7kn9/4/

Here is references: 1.https://jsfiddle.net/Fidel90/7kmf3jz2/ 2.https://codepen.io/keerotic/pen/yYXeaR

Many thanks.

//undo and redo
canvas.on('object:added', function() {
  if (!isRedoing) {
    h = [];
  }
  isRedoing = false;
});

var isRedoing = false;
var h = [];

function undo() {
  if (canvas._objects.length > 0) {
    h.push(canvas._objects.pop());
    canvas.renderAll();
  }
}

function redo() {

  if (h.length > 0) {
    isRedoing = true;
    canvas.add(h.pop());
  }
}

Try this https://github.com/lyzerk/fabric-history

Importing order

  1. fabric
  2. fabric-brush
  3. fabric-history

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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