如何让“Pointermove”委托在Safari iOS中的父/子上工作?

hxzsmxv2  于 5个月前  发布在  iOS
关注(0)|答案(1)|浏览(88)

我遇到了一个问题,还没有找到解决方法。我试图在父容器上使用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>
wsxa1bj1

wsxa1bj11#

看起来这个问题已经存在很长时间了。Touchmove的工作方式与pointermove相同,这就是为什么我没有看到这个问题的结果。下面是another stack overflow post的解决方法,即使用document.elementFromPoint,例如:

const outer = document.getElementById("outer");
outer.addEventListener("pointermove", (e) => {
    actualTarget = document.elementFromPoint(e.clientX, e.clientY);
    console.log(actualTarget.id);
})

字符串

相关问题