使用Fabric.js选择画布上的所有对象 [英] Select All the objects on canvas using Fabric.js
问题描述
有没有办法明确选择特定时刻出现的所有对象。
这可以通过鼠标轻松完成全部选择。是否有一个代码解决方案,如名为选择全部
的按钮,以便单击它将使所有结构类型对象被选中,然后我可以将更改应用于整个ActiveGroup使用 canvas.getActiveGroup();
并迭代。
Is there a way to explicitly select all the objects present at a particular instance of time.
This can be easily done using mouse to select all. Is there a code-solution like a button named Select All
so that clicking it would make all the fabric type objects being selected and then I could apply the changes to whole of that ActiveGroup using canvas.getActiveGroup();
and iterate over.
推荐答案
好问题。
这里没有内置的方法,但你需要按照以下方式做一些事情:
There's no built-in method for this, but you would need to do something along these lines:
var objs = canvas.getObjects().map(function(o) {
return o.set('active', true);
});
var group = new fabric.Group(objs, {
originX: 'center',
originY: 'center'
});
canvas._activeObject = null;
canvas.setActiveGroup(group.setCoords()).renderAll();
代码应该是不言自明的,当你使用鼠标时,它几乎就是在幕后发生的事情,shift + click等。
The code should be self-explanatory, and it's pretty much what's happening under the hood when you use mouse, shift+click, etc.
这篇关于使用Fabric.js选择画布上的所有对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!