问题
I am building a page that needs to work with touch and mouse interaction on PC, Mac, and mobile browsers.
In the event handler methods for touchStart, touchMove, touchEnd, and touchCancel I am calling event.preventDefault to prevent mobile browsers from firing both touch and mouse events.
This works great for mouseDown and mouseUp, which do not get fired when I touch the screen, but for some reason a short while (couple 100ms) after each touchStart is fired, the android browser still fires a mouseMove event (on the very first touchStart, this mouseMove is preceded by a mouseOver). If I touch quickly enough, the mouseMove gets fired after touchEnd (with the same delay relative to touchStart).
I'd really like to prevent any mouse events from being generated from touches and I'd also like to understand in detail what's going on here, so I have the following questions:
- Is there some other touch event that I am not capturing which causes the mouseMove event?
- Why is the mouseMove delayed a bit relative to the touch start?
- Why isn't the mouseMove generated by any other touch events (touchMove, touchEnd)?
- Do any other browsers have quirks that might generate mouse events from touches?
- Is there a different cross-platform approach for preventing touch to cause mouse events? Maybe some CSS?
来源:https://stackoverflow.com/questions/28665855/preventing-touch-from-generating-mouseover-and-mousemove-events-in-android-brows