2012-10-19 59 views
5

我正在使用Raphael JS 2.0,並且想要模擬另一個元素上的拖動結束,然後刪除正在處理的當前元素。如果可以使用jquery來完成,那也會很棒。如何模擬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')}); 
$(currentShift.node).mouseup(); 
child.remove(); 

我得到的錯誤,因爲子元素是一拖的「移動」部分this。但它被用於與currentShift進行交互。

我知道還有一些獲得類似效果的其他方法,但我想知道是否有某種方法可以模擬任意元素的拖動結束。

+0

可能是'var child = currentShift.data()。endChild;'...... –

+0

@eicto我真的不明白你的意思。 'child'元素設置正確。我真正想知道的部分是'$(currentShift.node).mouseup();'。這條線實際上並沒有調用該元素的結束拖動事件,或者至少它給我提供了錯誤,而不是像我期望的那樣釋放currentShift元素。 – keyneom

回答

1

看起來你可以(在我的情況up)與call()只是路過(在我的情況currentShift)到您的拉斐爾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(); 

這仍然是沒有做準確,因爲我想什麼,如果用戶一直按住鼠標下來,試圖調用元素一直是即使我拖移動功能(即它實際上並不強制拖動事件停止,它只是調用up事件,然後給出很多非致命錯誤,因爲在嘗試調用move函數時該元素不再存在。)

如果有人可以在接下來的幾天提供一個關於如何強制拖動結束的回答(因此不再需要對移動功能進行調用),即使用戶繼續按住鼠標,我也會接受這個答案。否則,我會接受這一點。

相關問題