2014-08-17

HTML5 JavaScript如何在Mobile Browser上偵測觸控 touchmove

在HTML5網頁動畫遊戲中用滑鼠來控制
但到了mobile browser 上就不管用, 手指滑動時只見網頁在移動.
在PC上,Browser JavaScript 用mousemove 來偵測滑鼠的移動訊號.
但到了  Mobile Browser 上後, 這招就不管用了.
這時我們該用touchmove來偵測手指點銀幕的信號: (見參考連結)
$(window).bind('touchmove', function(jQueryEvent) { jQueryEvent.preventDefault(); var event = window.event; $('#status').html('x='+event.touches[0].pageX + ' y= ' + event.touches[0].pageY); });

或是合併mousemove touchmove兩者一起偵測:



未處理touchmove 訊號前,手指點銀幕只見網頁會移動.
處理touchmove訊號後,我們的動畫會被訊號控制, 而網頁就不動了.

javascript - How to get continuous mousemove event when ...

stackoverflow.com/.../how-to-get-continuous-mousemove-...翻譯這個網頁
2011年6月11日 - ... to get continuous mousemove event when using android mobile browser? ... In Windows browser like firefox, It's ok to see the mouse postion ...

沒有留言:

張貼留言