我遇到了问题,但尚未找到解决方法。我正在尝试在父容器上使用带有
pointermove
的事件委托,我想知道事件何时从子容器跨越到父容器,反之亦然。
这在桌面浏览器上运行良好,但当我在 Safari iOS 中尝试时,事件目标似乎“卡在”首先启动
pointermove
的任何内容上。当 pointermove
跨越父/子边界时,目标不会改变。有什么想法吗?
示例代码:
const outer = document.getElementById("outer");
outer.addEventListener("pointermove", (e) => console.log(e.target.id))
body {
touch-action: none;
}
#outer {
height: 500px;
width: 500px;
background-color: #AAAAFF;
}
#inner {
height: 200px;
width: 200px;
background-color: #AAFFAA;
}
<div id="outer">
<div id="inner">
</div>
</div>
看来这个问题已经存在很长时间了。 Touchmove 的工作方式与
pointermove
相同,这就是为什么我没有看到这个问题的结果。这是另一个堆栈溢出帖子,其解决方法是使用document.elementFromPoint
,例如:
const outer = document.getElementById("outer");
outer.addEventListener("pointermove", (e) => {
actualTarget = document.elementFromPoint(e.clientX, e.clientY);
console.log(actualTarget.id);
})