Getting the current DOM object that is touching or touching

As Mozilla reports on the TouchEvent page:

The purpose of the event is the same element that received the touch start event corresponding to the touch point, even if the touch point has moved outside of this element.

This is not the same as mousemove and mouseup, where the target is really the DOM element that the mouse is over.

What is the best way, without using any library, to get the element in which the touchmove or touchend event touchend ?

+7
source share
1 answer

Read the coordinates ( pageX and pageY ) from the event object. Then use document.elementFromPoint(x, y) to get the top element at that position.

+6
source

All Articles