【问题标题】:Undo and redo on drawing board with Fabric.js and Fabric-brush.js使用 Fabric.js 和 Fabric-brush.js 在绘图板上撤消和重做
【发布时间】:2021-06-30 03:51:55
【问题描述】:

我用 Fabric.js 和 Fabric-brush.js 开发了一个绘图板。当我添加撤消和重做功能时,它们不起作用。但是当我不参考fabric-brush.js时它们可以工作。那么如何让fabric-brush.js 的Spray Brush 功能和Undo 和Redo 功能结合起来呢?

这是它的 Jsfiddle 链接:https://jsfiddle.net/Miamiaoke/x68v7kn9/4/

这里是参考: 1.https://jsfiddle.net/Fidel90/7kmf3jz2/ 2.https://codepen.io/keerotic/pen/yYXeaR

非常感谢。

//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());
  }
}

【问题讨论】:

    标签: javascript fabricjs


    【解决方案1】:

    试试这个https://github.com/lyzerk/fabric-history

    进口订单

    1. 面料
    2. 织物刷
    3. 面料历史

    【讨论】:

    • 感谢您的帮助!但是fabric-brush.js在导入顺序的demo上不起作用。
    猜你喜欢
    • 2014-10-11
    • 2013-09-30
    • 2014-04-15
    • 1970-01-01
    • 1970-01-01
    • 2013-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多