FabricJS:当用户选择多个对象时,不会触发object:moving事件 [英] FabricJS: object:moving event doesn't fire when user selects multiple objects

查看:656
本文介绍了FabricJS:当用户选择多个对象时,不会触发object:moving事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FabricJS中有一个object:moving事件,您可以为其触发一个函数,我已将其设置为保持线条与点的连接,就像在stickman演示中一样: http://fabricjs.com/stickman/

In FabricJS, there is an object:moving event you can fire a function for, which I have rigged up to keep lines attached to dots in the same way they have here in the stickman demo: http://fabricjs.com/stickman/

在他们的演示中,他们有通过单击并拖动点周围的正方形来选择点,然后通过单击并拖动来移动对象的选择。就我而言,我希望用户能够选择多个点并同时拖动它们,但是现在发生的是线与点断开了连接。此确切问题在下面的二次曲线示例中得到了说明: http://fabricjs.com/quadratic-curve/。一次选择两个点并拖动您的选择...它将断开点与线的连接。

In their demo, they have turned of the ability to select dots by clicking and dragging a square around them, then moving that selection of objects by clicking and dragging it. In my case, I want the user to be able to select multiple dots and drag them at the same time, but right now what's happening is that the lines disconnect from the dots. This exact issue is illustrated here in their quadratic curve example: http://fabricjs.com/quadratic-curve/. Select both dots at once and drag your selection... it will disconnect the dots from the line.

移动选区时,是否可以通过某种方式处理事件?似乎正在动态创建一个组,但是我尝试使用selection:created事件来获得该组的所有权,然后再次在该组中的每个对象上设置一个object:moving事件处理程序,但没有成功。这里有任何想法吗?

Is there some way to fig up an event when moving the selection? It seems to create a group on the fly, but I tried using the selection:created event to get a hold of that group and again set an object:moving event handler on each object in the group, with no success. Any ideas here?

推荐答案

您可以采用两种方法。


  1. 向画布添加 object:moving事件的侦听器。这将触发任何移动的对象或组。
    canvas1.on('object:moving',function(event){
    console.log( object:moving);
    });

创建选择组后,您可以将移动事件直接添加到该组中。

When a selection group is created you can add a moving event directly to the group.

canvas1.on('selection:created',function(event){
canvas1.getActiveGroup()。on('moving',function(event){
console.log('moving');
});
console.log( selection created);
});

这个小提琴有两个例子。
http://jsfiddle.net/pxnfbt89/

This fiddles has examples of both. http://jsfiddle.net/pxnfbt89/

这篇关于FabricJS:当用户选择多个对象时,不会触发object:moving事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆