简体   繁体   English

Fabric.js:无法再获得活动组

[英]Fabric.js: can't get the active groups anymore

I'm using fabric 1.4.10 and i noticed that i can't get the active groups anymore! 我正在使用结构1.4.10,我注意到我再也无法获得活动组了! Everytime i call canvas.getActiveGroup() even when a group is selected, i get null. 每当选择一个组时,我每次调用canvas.getActiveGroup()时,我都会为null。

My code to create groups: 我创建组的代码:

var circle1 = new fabric.Circle({
  radius: 50,
  fill: 'red',
  left: 0
});
var circle2 = new fabric.Circle({
  radius: 50,
  fill: 'green',
  left: 100
});
var circle3 = new fabric.Circle({
  radius: 50,
  fill: 'blue',
  left: 200
});

var group = new fabric.Group([ circle1, circle2, circle3 ], {
  left: 200,
  top: 100
});

canvas.add(group);

Can anyone help please? 有人可以帮忙吗?

This is because you have to check for "activeObject". 这是因为您必须检查“ activeObject”。

fabric.canvas.getActiveObject() will return the current selected object. fabric.canvas.getActiveObject()将返回当前选定的对象。

getActiveGroup will return a group if there is a temporary group selection made with interactivity layer. 如果使用交互层进行了临时组选择,则getActiveGroup将返回一个组。 ( mouse ) ( 老鼠 )

You can add these two lines code to try: 您可以添加以下两行代码来尝试:

canvas._activeObject = null;                    
canvas.setActiveGroup(group.setCoords()).renderAll();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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