简体   繁体   中英

Fabricjs removed selected object

How can I remove a selected Object in Fabric js

Currently I can remove one selected object like following:

function removeCurrentObject(canvas) {
    $('#remove-current-object').click(function() {
        canvas.getActiveObject().remove();
    });
}

But how can I check wether the user selectes more objects and remove them on an Event(click)

function removeCurrentObject(canvas) {
$('#remove-current-object').click(function() {
  if(canvas.getActiveGroup()) {
    var objs = canvas.getActiveGroup();
    canvas.discardActiveGroup();
    objs.forEachObject(function(o) {
    canvas.remove(o)
   });
  } else {
   canvas.remove(canvas.getActiveObject());
  }
  });
}

check if any active group there, if present remove one by one object from group

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