I build a web mobile game, it runs on browsers (PC/Mobile).
Do I need to use the touchmove
or not?
How can I run the touchmove
event like the mousemove
event?
MouseMove is a simple event that is executed when a pointer is moving over or around an element. Mousemove is a javascript event that inside a web page. The mousemove event can also be understood as a part of an event handler, whereupon some action or movement by a mouse pointer, an intended script is executed.
The jQuery Mobile vmousemove event handler simulates the "onmousemove" event handler on mobile devices. This plugin extends jQuery's built-in method. If jQuery Mobile is not loaded, calling the . vmousemove() method may not fail directly, as the method still exists.
onTouchStart works only for mobile. Also, this event goes before the onClick event.
As we move the mouse, a line is drawn on the canvas between the current and the previous mouse position. When we release the mouse (mouseup event), drawing stops. We will demonstrate this application using Mouse Events, Touch Events and finally combining both with Pointer Events.
Definition and Usage The touchmove event occurs when the user moves the finger across the screen. The touchmove event will be triggered once for each movement, and will continue to be triggered until the finger is released. Note: The touchmove event will only work on devices with a touch screen.
Web applications wanting to handle mobile devices use Touch Events (touchstart, touchup, touchmove). But in addition to handling touch, they must handle mouse input as well. So to do the same job, they have to duplicate the code or bring an unnecessary if-else to handle both mouse and touch.
The behavior of these events is very close, but subtly different - in particular, touch events always target the element where that touch STARTED, while mouse events target the element currently under the mouse cursor. This is why we have mouseover and mouseout events, but there are no corresponding touchover and touchout events - only touchend.
For parity between desktop and touch you have the following equivalences:
mousedown === touchstart mousemove === touchmove mouseup === touchend
Thus if you handle mousedown
, mousemove
and mouseup
then you don't need to handle the corresponding equivalent events under touch. The same handlers should be executing.
Except on the ipad -- where mouse hover, mouse down, mouse up and click are all triggered... except if you change anything in mouse hover .. then nothing else gets triggered.... very annoying...more details see http://sitr.us/2011/07/28/how-mobile-safari-emulates-mouse-events.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With