2014-02-26 205 views
0

我已經將mousemove和mousedown事件綁定到div元素,如下所示。在Firefox中,每當我將手指移動到div元素上時,該事件都會觸發。但在ie/chrome中,事件只會在第一次觸發div時觸發,在div上連續移動手指,並不會像在Firefox中觸發事件。觸摸屏事件

this._on(this.element, 'mousemove', this.chartMouseMove); 
this._on(this.element, 'mousedown', this.chartMousedown); 

注意:鼠標事件被觸發(移動鼠標指針觸發事件),只有觸摸沒有工作(移動手指doent工作)。

我想鼠標移動得到觸發,當我移動手指提前

+0

如果它對你有效,你應該接受答案。 – Alvaro

回答

2

感謝您應該使用touchmovetouchStart觸摸設備。

this._on(this.element, 'touchmove', this.chartMouseMove); 
this._on(this.element, 'touchstart', this.chartMousedown); 

如果你想讓它隨着Windows Phone兼容,那麼你也應該補充MSPointerDownMSPointerMove

this._on(this.element, 'touchmove MSPointerMove', this.chartMouseMove); 
this._on(this.element, 'touchstart MSPointerDown', this.chartMousedown); 

如果你需要處理的Windows 8觸摸屏設備,那麼你就需要與addEventHandler而不是on

this.element.addEventListener("MSPointerMove", this.chartMouseMove); 
this.element.addEventListener("MSPointerDown", this.chartMousedown); 

此外,您將需要應用下面的風格在你的身體:

body{ 
    -ms-touch-action: none; 
} 

如果你不介意使用插件的話,我會建議你使用hand.js使它很簡單:)

+0

感謝您的更新,但這不起作用。每當我觸摸div(即mouseDown正在工作)時,我會調用chartMousedown方法,爲什麼mouseMove不起作用 – user3326265

+0

@ user3326265您正在使用哪種觸摸設備? – Alvaro

+0

帶窗戶的觸控筆8 – user3326265