正如 Mozilla 在 TouchEvent 上所说的那样页:
The event's target is the same element that received the touchstart event corresponding to the touch point, even if the touch point has moved outside that element.
这与 mousemove
和 mouseup
不同,后者的目标实际上是鼠标悬停的 DOM 元素。
在不使用任何库的情况下获取发生我的 touchmove
或 touchend
事件的元素的最佳方法是什么?
最佳答案
从事件对象中读取坐标(pageX
和 pageY
)。然后使用 document.elementFromPoint(x, y)
获取该位置的顶部元素。
关于javascript - 获取 touchmove 或 touchend 结束的当前 DOM 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10506463/