Shouldn't touchmove trigger mousemove automatically?

1.4k views Asked by At

The Mozilla Developer Network says:

(...) even if a browser supports touch, the browser must still emulate mouse events so content that assumes mouse-only input will work as is without direct modification.

In my application, a touchstart event triggers the mousedown event. However, a touchmove event is not triggering the mousemove event (I just added an alert in the beginning of my mouseMove function, and it's never called).

The relevant lines of my code are:

<html onmousemove='mouseMove(event)' onmouseup='mouseUp(event)'>

<canvas onmousedown='cnvMouseDown(event)'></canvas>

The mouseMove and mouseUp functions are on the html element, so they'll work even if the cursor moves outside the canvas. Shouldn't this mouseMove be automatically caught by the html's touchmove event? Why isn't it?

1

There are 1 answers

4
M A Salman On

MDI-"even if a browser supports touch, the browser must still emulate mouse events so content that assumes mouse-only input will work as is without direct modification"

It means if there is a browser that supports touch,it is must and recommended for that browser to emulate mouse events too so that if there are any scenarios which are associated with mouse events , those will work without having to explicitly handle them.

As of the mousemove and touchmove ,they are not the same.

"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."

Hope this helps