当用单个手指在元素上滑动手势时,浏览器将触发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中停止窗口滚动,但不会触发鼠标移动或触摸移动事件。 (如果你水平滑动而不是垂直滑动,鼠标移动会发光)
答案 0 :(得分:0)
触摸事件目前在桌面版Firefox(36.0.4)中被禁用,但它们在Metro模式下运行Firefox时可以正常工作,或者通过dom.w3c_touch_events.enabled
设置明确启用它们。有关详细信息,请参阅the MDN article on Touch events。