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?
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?
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.
mousedown
+ mousemove
+ mouseup
, but when I use my app on a touch device, none of them fire. This may be either (1) browser-specific, (2) due to synthetic event handler behavior in React, or perhaps (3) a result of some CSS properties like e.g. touch-action
. Any clarification under which circumstances this statement holds would be appreciated. –
Pupil 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
you can use both in one component (w.r.t react)
for eg:
<component onMouseMove={handleMouseMove} onTouchMove={handleMouseMove} />
on the bases of screen which is being used react will automatically switch either option of mouse or touch
or you can also use
("ontouchstart" in document.documentElement)
it gives true for touch screen device and vice versa
ref: https://codepen.io/tteske/pen/KKwxOxp
© 2022 - 2025 — McMap. All rights reserved.