简体   繁体   English

Fabric.js在组之后插入

[英]Fabric.js insert after group

I have rendered a complex canvas with several layers of Fabric.js Groups, PathGroups and Paths. 我绘制了一个复杂的画布,其中包含Fabric.js组,PathGroups和Paths的几层。 Many of the elements are selectable and when they are selected they should be highlighted. 许多元素都是可选的,选择它们时应突出显示。

Right now I'm rendering all the possible highlights together with the foundation, before the selectable objects. 现在,我正在将所有可能的高光与基础一起渲染到可选对象之前。 Really what I would prefer is to render the highlight simply when someone clicks on a Group or Path. 我真正希望的是仅在有人单击“组”或“路径”时才渲染高光。 For this I would need to insert the highlight below the selection, so is there a way of inserting a Path before a Group or another way of doing this? 为此,我需要在选区下方插入突出显示的内容,那么有没有办法在Group之前插入Path或另一种方式呢?

Please notice, I'm not looking for element.sendBackwards(true); 请注意,我不是在寻找element.sendBackwards(true); because there is not always the same amount of elements that the highlight should be bellow. 因为突出显示的元素并不总是相同。

I found out that it is possible to get the index of an element and move an element to a specific index! 我发现可以获取元素的索引并将元素移至特定索引! Problem solved. 问题解决了。

var index = canvas.getObjects().indexOf(group1); 
canvas.moveTo(group2, index);

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

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