如果可以使用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交互。
我知道还有其他一些方法可以获得类似的效果,但我想知道是否有一些方法可以模仿任意元素的拖曳末端。
发布于 2012-10-20 08:24:43
看起来您可以通过call()使用对拖动结束函数的引用(在我的示例中为up),只需将一个引用(在我的示例中为currentShift)传递给您的Raphael元素。我的代码现在看起来像这样:
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();这仍然不是我想要的,因为如果用户一直按住鼠标,即使在元素被移除之后,它也会尝试调用我的拖动移动函数(即,它实际上并没有强制拖动事件停止,它只是调用了up事件,然后给出了许多非致命的错误,因为当尝试调用移动函数时,该元素不再存在。)
如果有人能在未来几天内回答如何强制拖动结束(这样就不会再调用move函数),即使用户继续按住鼠标,我也会接受这个答案。否则,我就接受这个。
https://stackoverflow.com/questions/12982996
复制相似问题