Sim*_*ris 6 javascript firefox windows-8.1
当在一个元素使的用单个手指滑动手势,浏览器将会触发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.
Run Code Online (Sandbox Code Playgroud)
因为我阻止了默认操作wheel,所以当单指向上或向下滑动时,滚动页面会停止
如果您在红色框中滑动,则在Firefox中停止窗口滚动,但不会触发mousemove或touchmove事件.(如果你水平滑动而不是垂直滑动,鼠标移动会触发)
触摸事件目前在桌面版 Firefox (36.0.4) 中被禁用,但在 Metro 模式下运行 Firefox 时或通过设置显式启用它们时,触摸事件将起作用dom.w3c_touch_events.enabled。有关更多信息,请参阅有关触摸事件的 MDN 文章。
| 归档时间: |
|
| 查看次数: |
717 次 |
| 最近记录: |