问题描述
有没有办法显式选择在特定时间实例中存在的所有对象.这可以很容易地使用鼠标选择所有.是否有一个代码解决方案,例如一个名为 Select All 的按钮,以便单击它会使所有织物类型对象都被选中,然后我可以使用 canvas 将更改应用于整个 ActiveGroup.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 选择画布上的所有对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)