简体   繁体   English

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

[英]How to simulate a drag end event in Raphael JS?

I'm using Raphael JS 2.0 and would like to simulate the end of a drag on another element and then remove the current element being handled. 我正在使用Raphael JS 2.0,并希望模拟另一个元素上拖动的结束,然后删除当前正在处理的元素。 If it can be done using jquery that would be great as well. 如果可以使用jquery完成,那也很棒。

Something like this: 像这样的东西:

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();

I get errors because the child element is the this in the "move" part of a drag. 我得到错误,因为子元素是拖动的“移动”部分中的this元素。 But it is being used to interact with currentShift . 但它被用于与currentShift交互。

I know there are some other methods of getting a similar effect, but I would like to know if there is some way to imitate the drag end for an arbitrary element. 我知道还有一些其他方法可以获得类似的效果,但我想知道是否有某种方法可以模仿任意元素的拖拽结束。

It looks like you can use a reference to your drag end function (in my case up ) with call() just passing a reference (in my case currentShift ) to your Raphael JS element. 它看起来像你可以用你的拖动结束函数的引用(在我的情况up ),用call()只是传递引用(在我的情况currentShift )到您的拉斐尔JS元素。 My code now looks like this: 我的代码现在看起来像这样:

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();

This still isn't doing exactly what I would like since, if the user keeps holding the mouse down, it attempts to call my drag move function even after the element has been removed (ie it isn't actually forcing the drag event to stop, it is just calling the up event and then giving a lot of non-fatal errors since the element doesn't exist any more when trying to call the move function.) 这仍然没有完全符合我的要求,因为如果用户一直按住鼠标,它会尝试调用我的拖动移动功能,即使在元素被移除后(即它实际上并没有强制拖动事件停止) ,它只是调用up事件然后给出了很多非致命错误,因为在尝试调用move函数时元素不再存在。)

If anybody can provide an answer in the next few days as to how to force the drag to end (so no more calls are made to the move function), even if the user continues to hold the mouse down, I will accept that answer. 如果有人能在接下来的几天内提供关于如何强制拖动结束的答案(因此不再调用移动功能),即使用户继续按住鼠标,我也会接受这个答案。 Otherwise, I'll just accept this. 否则,我会接受这个。

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

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