我正在使用 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();
我收到错误是因为子元素是拖动的“移动”部分中的 this
。但它正用于与 currentShift
交互。
我知道还有其他一些方法可以获得类似的效果,但我想知道是否有某种方法可以模仿任意元素的拖动端。
最佳答案
看起来您可以通过 call()
使用对拖动结束函数的引用(在我的例子中为 up
),只需传递一个引用(在我的例子中为 >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();
这仍然不是我想要的,因为如果用户一直按住鼠标,它会尝试调用我的拖动移动功能,即使元素已被删除(即它实际上并没有强制拖动事件停止,它只是调用向上事件,然后给出很多非 fatal error ,因为在尝试调用移动函数时该元素不再存在。)
如果有人能在接下来的几天内提供关于如何强制结束拖动的答案(这样就不会再调用移动功能),即使用户继续按住鼠标,我也会接受那个答案。否则,我会接受这个。
关于javascript - 如何在 Raphael JS 中模拟拖动结束事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12982996/