触摸屏中的事件 [英] Events in touch screen
问题描述
我已经将mousemove和mousedown事件绑定到div元素,如下所示.在firefox中,每当我将手指移到div元素上时,事件get就会触发.但是在ie/chrome中,仅当我触摸div时,该事件仅在div上连续移动手指时才触发,不会像在Firefox中那样触发该事件.
i have bind an mousemove and mousedown event to a div element, as below. In firefox, the event get triggers each time when i moved my finger over the div element. but in ie/chrome, the event gets triggered only for first time when i touch the div, moving the finger continuously over the div, doesnt trigger the event as in firefox.
this._on(this.element, 'mousemove', this.chartMouseMove);
this._on(this.element, 'mousedown', this.chartMousedown);
注意:触发了鼠标事件(移动鼠标指针会触发事件),只有触摸不起作用(移动手指才起作用).
Note: Mouse event are triggered(moving mouse pointer triggers the event), only the touch is not working(moving fingers doent work).
当我移动手指时,我希望mousemove能够触发
I want the mousemove to get trigger, when i moved the finger
预先感谢
推荐答案
对于触摸设备,应使用touchmove
和touchStart
.
For touch devices you should use touchmove
and touchStart
.
this._on(this.element, 'touchmove', this.chartMouseMove);
this._on(this.element, 'touchstart', this.chartMousedown);
如果要使其与Windows Phone兼容,则还应该添加MSPointerDown
和MSPointerMove
:
And if you want to make it compatible with Windows Phone, then you should also add MSPointerDown
and MSPointerMove
:
this._on(this.element, 'touchmove MSPointerMove', this.chartMouseMove);
this._on(this.element, 'touchstart MSPointerDown', this.chartMousedown);
如果您需要处理Windows 8触摸设备,则需要使用addEventHandler
而不是on
.
If you need to deal with Windows 8 touch devices, then you would need to work with addEventHandler
instead of with on
.
this.element.addEventListener("MSPointerMove", this.chartMouseMove);
this.element.addEventListener("MSPointerDown", this.chartMousedown);
此外,您将需要在身体中应用以下样式:
Also, you will need to apply the following style in your body:
body{
-ms-touch-action: none;
}
如果您不介意使用插件,我建议您使用 hand.js
使其变得简单:)
If you don't mind using plugins for it, I would recommend you to make use of hand.js
to make it simple :)
这篇关于触摸屏中的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!