【问题标题】:Surface Pro 3 with Firefox - Have single touch trigger touch/mouse events instead of wheel events带有 Firefox 的 Surface Pro 3 - 具有单点触摸触发触摸/鼠标事件而不是滚轮事件
【发布时间】:2015-03-03 09:52:44
【问题描述】:

仅在带有 Firefox 的 Surface Pro 3 上:

当用单指在元素上滑动手势时,浏览器将触发wheel 事件,而不是touchmovemousemove 事件。您如何停止滚轮行为,并允许始终将单个手指视为触摸/鼠标移动?

所以我想将单指滑动视为一系列mousemovetouchmove,而不是wheel 事件。如果在此元素上滑动,我根本不希望单指滑动来滚动页面。这在 Chrome 和 IE11 中很容易做到。现在在 Firefox 中这似乎是不可能的。目前我认为这是一个错误,但我可能缺少一些东西。

这是一个简单的例子:

http://codepen.io/simonsarris/pen/PwbdRZ

var can = document.getElementById('can');

can.addEventListener('mousemove', function(e) {
  // Will never happen on the Surface Pro 3 in Firefox
  // Will happen in IE11 though
  console.log('mouseMove')
});

can.addEventListener('touchmove', function(e) {
  // Will never happen on the Surface Pro 3 in Firefox
  // Will happen in Chrome though
  console.log('touchMove')
});

// Stops the window from scrolling in firefox when you swipe on the element
// But stopping this does not allow the single touch gesture to register as mousemove or touchmove events
can.addEventListener('wheel', function(e) {
  console.log('wheel')
  e.preventDefault();
});


// consider also the 'DOMMouseScroll' event, though preventing this event will not stop firefox from panning the page.

因为我在wheel 中阻止默认设置,所以当单指向上或向下滑动时页面会停止滚动

如果您在红色框内滑动,则窗口滚动在 firefox 中停止,但不会触发 mousemove 或 touchmove 事件。 (但是,如果您水平滑动而不是垂直滑动,mousemove 会触发)

【问题讨论】:

  • 我无权访问硬件,所以我无法自己测试,但你在听touchstart吗? MDN page 似乎暗示如果您阻止默认设置,您不会 获得鼠标事件 - 并且可能是鼠标滚动事件正在抑制 touchmove

标签: javascript firefox windows-8.1


【解决方案1】:

触摸事件目前在 Firefox 桌面版 (36.0.4) 中被禁用,但在 Metro 模式下运行 Firefox 或通过dom.w3c_touch_events.enabled 设置显式启用它们时它们将起作用。请参阅the MDN article on Touch events 了解更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多