I am currently working on implementing a drag and drop user interface for my web application. The goal is to allow users to drag an item using either a mouse or their finger, and then drop it into one of several designated zones. While the functionality works smoothly with mouse events, I have encountered challenges when dealing with touch events on iPhones and iPads.
The issue arises when the ontouchmove event handler is triggered for an item - the event.touches[0].target always refers back to the original HTML element (the dragged item) instead of the current element under the finger. Additionally, the touchmove handlers for the drop zones do not get activated as the item is dragged over them by a finger. This makes it difficult to determine when a finger is hovering over a drop zone in order to highlight it appropriately. In contrast, when using a mouse, the mousedown event correctly triggers for all elements beneath the cursor.
Some sources suggest that this behavior is characteristic of iPhone touch events, as explained in this article: "For those familiar with traditional web design, the target attribute in mousemove events usually reflects the element currently being hovered over by the mouse. However, in iPhone touch events, the target points back to the initial node where the touch began."
Question: Is there a workaround or method to accurately identify the element currently touched by a finger (as opposed to the originally touched element which may vary)?