【发布时间】:2015-03-03 09:52:44
【问题描述】:
仅在带有 Firefox 的 Surface Pro 3 上:
当用单指在元素上滑动手势时,浏览器将触发wheel 事件,而不是touchmove 或mousemove 事件。您如何停止滚轮行为,并允许始终将单个手指视为触摸/鼠标移动?
所以我想将单指滑动视为一系列mousemove 或touchmove,而不是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