如何在Raphael JS中模拟拖动结束事件?

key*_*eom 5 javascript jquery raphael drag

我正在使用Raphael JS 2.0,并希望模拟另一个元素上拖动的结束,然后删除当前正在处理的元素.如果可以使用jquery完成,那也很棒.

像这样的东西:

var child = currentShift.data('endChild');
var newX = child.attr('x');
if (this !== currentShift)
{
    newX = child.attr('x')-day;
}
currentShift.attr({y: child.attr('y'), x: newX, height: child.attr('height')});
$(currentShift.node).mouseup();
child.remove();
Run Code Online (Sandbox Code Playgroud)

我得到错误,因为子元素是this拖动的"移动"部分.但它被用来与之互动currentShift.

我知道还有一些其他方法可以获得类似的效果,但我想知道是否有某种方法可以模仿任意元素的拖拽结束.

key*_*eom 1

看起来您可以使用对拖动结束函数(在我的例子中up)的引用,call()只需将引用(在我的例子中currentShift)传递给 Raphael JS 元素。我的代码现在看起来像这样:

var child = currentShift.data('endChild');
var newX = child.attr('x');
if (this!==currentShift)
{
    newX = child.attr('x')-day;
}
currentShift.attr({y: child.attr('y'), x: newX, height: child.attr('height')});
if (this !== currentShift)
    up.call(child);
else
    up.call(currentShift);
child.remove();
Run Code Online (Sandbox Code Playgroud)

这仍然没有完全达到我想要的效果,因为如果用户继续按住鼠标,即使在元素被删除之后它也会尝试调用我的拖动移动函数(即它实际上并没有强制拖动事件停止,它只是调用 up 事件,然后给出很多非致命错误,因为在尝试调用 move 函数时该元素不再存在。)

如果有人可以在接下来的几天内提供关于如何强制结束拖动的答案(因此不再调用移动函数),即使用户继续按住鼠标,我也会接受该答案。否则,我就接受这个。