javascript - 适用于不同浏览器和设备的鼠标和触摸事件

标签 javascript jquery touch

我在页面中有 div 元素并绑定(bind)了以下事件

/

/ 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);
        }

触摸 div 并连续移动时,div 必须根据我的手指在页面上的位置移动。这在 firefox、chrome、safari 中工作正常,但在 IE 浏览器中不起作用(使用鼠标拖动 div 可以工作,通过触摸则不起作用)。

我在所有鼠标处理程序中使用了以下代码:例如。

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

使用触摸支持移动 div 时,整个页面在 IE 浏览器中上下移动,正在发生默认操作,我是否错过了 IE 浏览器的任何操作?

请解释如何处理不同浏览器和设备(手机|平板电脑|android)的触摸和鼠标事件。

提前致谢

最佳答案

您是否尝试过添加 -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.

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

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

关于javascript - 适用于不同浏览器和设备的鼠标和触摸事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22068133/

相关文章:

ios - 有什么方法可以让 iOS 中的触摸保持活力?

javascript - 如何从应用于正文的 css 中排除特定的表单

javascript - 如何使用 javascript/jquery 从数组中获取最大和最小日期?

jquery - 当向我的表单集中添加新的内联时,我的日期选择器停止工作

jquery - jQuery 可以将 ViewModel 发送到 ASP.NET MVC 中的 Controller 吗?

css - 将触摸/滑动命令添加到 CSS 转换/动画

JavaScript 拖放不适用于 iPad

javascript - 如何限制多个文本区域的字数?

javascript - 无法理解递归的逻辑

javascript - 如何使用 fetch 从 promise 回调返回?