Select All the objects on canvas using Fabric.js(使用 Fabric.js 选择画布上的所有对象)
问题描述
有没有办法显式选择在特定时间实例中存在的所有对象.这可以很容易地使用鼠标选择所有.是否有一个代码解决方案,例如一个名为 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 选择画布上的所有对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Fabric.js 选择画布上的所有对象


基础教程推荐
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01