Undo-Redo feature in Fabric.js

前端 未结 9 745
梦谈多话
梦谈多话 2020-12-04 13:28

Is there any built-in support for for undo/redo in Fabric.js? Can you please guide me on how you used this cancel and repeat in [http://printio.ru/][1]

9条回答
  •  青春惊慌失措
    2020-12-04 13:55

    I am allowing the user to remove the last added path (in my painting application), this works fine for me:

    var lastItemIndex = (fabricCanvas.getObjects().length - 1);
    var item = fabricCanvas.item(lastItemIndex);
    
    if(item.get('type') === 'path') {
      fabricCanvas.remove(item);
      fabricCanvas.renderAll();
    }
    

    But you could also remove the IF statement and let people remove anything.

提交回复
热议问题