I have a simple UI that allows users on desktop browsers to click on a cell in a grid, and while holding the mouse button down, move the mouse around to highlight multiple cells very quickly. I accomplish this with mousedown
, mouseover
and mouseup
events on the document
, and using a Boolean flag to dictate whether the mouse button is being held down our not. It works fine on desktop browsers.
The problem is with mobile browsers though. Those mouse events don't exist, and I know we need to use the touch
events instead, but after extensive searching around Google, SO, etc., I cannot find a consistent, workable way to do the same sort of thing on mobile browsers.
The closest I've seen is capturing the start with touchstart
, and then tracking finger movement with touchmove
and the evt.touches[0].clientX/Y
properties. Is there a better/simpler way to do this, or are we forced to basically check screen coordinates with clientX/Y
to figure out which DOM element we're "hovering over" and highlighting the DOM element accordingly?