触摸屏事件
我已经将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工作)。
我想鼠标移动得到触发,当我移动手指提前
感谢您应该使用touchmove
和touchStart
触摸设备。
this._on(this.element, 'touchmove', this.chartMouseMove);
this._on(this.element, 'touchstart', this.chartMousedown);
如果你想让它随着Windows Phone兼容,那么你也应该补充MSPointerDown
和MSPointerMove
:
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
使它很简单:)
感谢您的更新,但这不起作用。每当我触摸div(即mouseDown正在工作)时,我会调用chartMousedown方法,为什么mouseMove不起作用 – user3326265
@ user3326265您正在使用哪种触摸设备? – Alvaro
带窗户的触控笔8 – user3326265
如果它对你有效,你应该接受答案。 – Alvaro