2015-01-05 96 views
6

在表面臨3只的Firefox:

當在元件製作用單個手指滑動手勢,瀏覽器將火wheel事件而不是touchmovemousemove事件。你如何停止車輪的行爲,並允許一個手指始終被視爲觸摸/鼠標移動?表面臨3與Firefox - 有單次觸摸的觸發的觸摸/鼠標事件,而不是輪事件

所以我想要將一個手指輕掃作爲一系列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會觸發)

+0

我無法訪問硬件,因此我無法自己測試,但是您是否正在傾聽'touchstart'? [MDN頁面](https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Touch_events)似乎意味着如果你防止默認,你*不會*獲得鼠標事件 - 可能是鼠標滾動事件正在壓制'touchmove'。 – Jeremy

回答

0

桌面版Firefox(36.0.4)當前禁用了觸摸事件,雖然它們可以在Metro模式下運行Firefox或通過明確啓用它們dom.w3c_touch_events.enabled設置。有關更多信息,請參閱the MDN article on Touch events