简体   繁体   English

鼠标和触摸各种浏览器和设备的事件

[英]Mouse and touch Events for varies browser and devices

i am having div element in a page and binded the following events 我在页面中有div元素并绑定了以下事件

/ /

/ for ie9, safari, mozilla
    this._on(this.element, "mousedown", this.chartMouseDown);
    this._on(this.element, "mouseup", this.chartMouseUp);
    this._on(this.element, 'mousemove', this.chartMouseMove);

  // for chrome
      this._on(this.element, 'touchmove', this.chartTouchMove);
      this._on(this.element, 'touchstart', this.chartTouchClick);
      this._on(this.element, 'touchend', this.chartTouchClick);

    if (window.navigator.msPointerEnabled) {
            this._on(this.element, 'MSPointerMove', this.chartMouseMove);
            this._on(this.element, 'MSPointerDown', this.chartMouseClick);
        }

On touching the div and continousous move, the div have to move according to my finger position on the page. 在触摸div和连续移动时,div必须根据我在页面上的手指位置移动。 This working fine in firefox, chrome, safari, but not in IE browser (dragging the div using mouse is working, by touch it is not working). 这在firefox,chrome,safari中运行良好,但不在IE浏览器中(使用鼠标拖动div正在工作,通过触摸它不起作用)。

i have used the following code in all the mouse handler: for example. 我在所有鼠标处理程序中使用了以下代码:例如。

chartMouseMove: function (e) {
        e.stopPropagation();
        e.preventDefault();
        e.returnValue = false;
        e.cancelBubble = true;
}

On moving the div using touch support, the entire page is moving up and down in IE browser, the default action is taking place, whether i missed any thing for IE browser? 在使用触摸支持移动div时,整个页面在IE浏览器中上下移动,默认动作正在发生,我是否错过了IE浏览器的任何东西?

Please explain how to handle touch and mouse event for varies browser and devices(mobile|tablet|android). 请解释如何处理各种浏览器和设备(手机|平板电脑| android)的触摸和鼠标事件。

Thanks in advance 提前致谢

Have you tried adding the -ms-touch-action style? 您是否尝试过添加-ms-touch-action样式?

To improve the performance of touch interactions, it is now required that you add to the intended touch target a CSS property that disables the default touch actions. 为了提高触摸交互的性能,现在需要向预期的触摸目标添加禁用默认触摸操作的CSS属性。

#touchTarget {
-ms-touch-action: none;
}

More info: http://blogs.msdn.com/b/ie/archive/2011/10/19/handling-multi-touch-and-mouse-input-in-all-browsers.aspx 更多信息: http//blogs.msdn.com/b/ie/archive/2011/10/19/handling-multi-touch-and-mouse-input-in-all-browsers.aspx

Apart from what @Dieter said, you will need to use addEventHandler instead of $(document).on for Windows 8 devices as I pointed out the other day in your question . 除了@Dieter所说的,你需要在Windows 8设备中使用addEventHandler而不是$(document).on ,正如我在你的问题中指出的那样

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

And then add: 然后添加:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM