Search code examples
javascriptiostouchmobile-safaridom-events

ontouchmove: Detecting the new element being touched when moving a touch across multiple elements


As far as I can tell, the event triggered by ontouchmove in mobile Safari only contains information about on which element the touch began. For example, let's assume I put my finger down on the element .firstElement and then drag it across the page until it is over .secondElement. I've inspected all the properties of the event object, but I can only seem to find references the .firstElement.

Is there a way to detect with ontouchmove which element the user's finger is currently touching?


Solution

  • This appears to be a duplicate of How to find out the actual event.target of touchmove javascript event?

    According to that answer, there is no data in the event object that references the element that the finger is currently over. You can, however determine it with the following code:

    var secondElement = document.elementFromPoint(event.clientX, event.clientY);