[英]Deselect a selected object in Fabric.js
I have multiple type objects on my canvas. 我的画布上有多个类型对象。 I can do scaling, rotation, etc. everything on a particular object.
我可以在特定对象上进行缩放,旋转等所有操作。
But when I select a particular object, I want to change its stroke
color. 但是当我选择一个特定的对象时,我想改变它的
stroke
颜色。
canvas.observe('mouse:down', function(e) {
activeInstance = canvas.getActiveObject();
activeGroupInstance = canvas.getActiveGroup();
if (activeInstance!=null){
activeInstance.set("stroke","#FF0000");
}
}
The code works well. 代码效果很好。 But the issue is that the
stroke
color or any other valid property
doesn't reflect directly which means I have to deselect a currently selected object to see the change in its properties. 但问题是
stroke
颜色或任何其他有效property
不直接反映,这意味着我必须取消选择当前选定的对象以查看其属性的更改。 So my question is what's going wrong? 所以我的问题是出了什么问题? If this is the usual behavior that we have to deselect/click the selected object, then, how to deselect the selected object using code ie without using mouse clicks simply using a code-snippet.
如果这是我们必须取消选择/单击所选对象的常见行为,那么,如何使用代码取消选择所选对象,即不使用鼠标单击只需使用代码片段。
We can use below mentioned solutions. 我们可以使用以下解决方案。
To discard all active groups you can use below function.Discards currently active group and fire events If the function is called by fabric as a consequence of a mouse event, the event is passed as a parmater and sent to the fire function for the custom events. 要丢弃所有活动组,您可以在函数下面使用.Discards当前活动组和激活事件如果由于鼠标事件而由Fabric调用该函数,则该事件将作为parmater传递并发送到fire函数以进行自定义事件。 When used as a method the e param does not have any application.
当用作方法时,e param没有任何应用。
canvas.discardActiveGroup();
To discard sigle object you can use like this. 要丢弃sigle对象,您可以像这样使用。 Discards currently active object and fire events.
丢弃当前活动的对象和火灾事件。 If the function is called by fabric as a consequence of a mouse event, the event is passed as a parmater and sent to the fire function for the custom events.
如果由于鼠标事件而由fabric调用该函数,则该事件将作为parmater传递并发送到fire函数以获取自定义事件。 When used as a method the e param does not have any application.
当用作方法时,e param没有任何应用。
canvas.discardActiveObject();
And i the last finally renders both the top canvas and the secondary container canvas like this. 我最后一次最终渲染顶部画布和辅助容器画布。
canvas.renderAll();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.