2016-12-15 63 views
2

code link爲什麼不能removeEventListener

我想,當鼠標鬆開事件觸發刪除鼠標懸停事件,但爲什麼不能revomeEventListener以及如何解決它,看起來這是我在javascript薄弱環節。

+0

請在您的問題實際的代碼,代碼沒有鏈接,以提高獲取高質量的答案的機會。 –

回答

0

在你fnDown您設置的事件監聽器是在dragBox但你嘗試從dragArea稍後將其刪除。您需要將偵聽器附加到dragArea如果您打算將其從中刪除。此功能按預期工作。

Drag.prototype.fnDown = function (e) { 
     this.diff.x = e.clientX - this.dragBox.offsetLeft 
     this.diff.y = e.clientY - this.dragBox.offsetTop 
     this.dragArea.addEventListener('mousemove', this.fnMove,false) 
    } 

工作例如: http://jsbin.com/dugoxeziho/1/edit?html,output

+0

謝謝,我太不小心瞭解它 – Yile