javascript - 获取 touchmove 或 touchend 结束的当前 DOM 对象

标签 javascript dom dom-events

正如 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.

这与 mousemovemouseup 不同,后者的目标实际上是鼠标悬停的 DOM 元素。

在不使用任何库的情况下获取发生我的 touchmovetouchend 事件的元素的最佳方法是什么?

最佳答案

从事件对象中读取坐标(pageXpageY)。然后使用 document.elementFromPoint(x, y)获取该位置的顶部元素。

关于javascript - 获取 touchmove 或 touchend 结束的当前 DOM 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10506463/

相关文章:

javascript - 避免 React setState() 回调循环

php - 如何使用对象作为 PHP 的 createElement 的参数

javascript - 如何禁止人们保存我网站的源代码?

javascript - 在javascript中动态分配和定位DIVS

javascript - 输入类型中的值在等待函数后不显示

javascript - 如何删除使用闭包添加的 EventListener?

javascript - 只能通过 Jenkins 部分运行 Protractor 测试

jquery - 将 jQuery 事件绑定(bind)到元素的最佳方法是什么

javascript - React JS将 'disabled'类添加到多个索引