触摸屏事件

问题描述:

我已经将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

感谢您应该使用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