gpt4 book ai didi

javascript - 为什么 document.elementFromPoint 找不到最顶层的元素?

转载 作者:行者123 更新时间:2023-11-28 04:33:50 24 4
gpt4 key购买 nike

document.elementFromPoint 的文档中它指出:

Returns the element from the document whose elementFromPoint method is being called which is the topmost element which lies under the given point.

但我没有看到这种行为。相反,它似乎选择了最底部的元素。这实际上是我想要的行为,但我担心为什么它与文档不匹配,我想了解原因以防止将来可能出现的错误。

我创建了 a fiddle to demonstrate this .如果您单击粗体但非斜体的文本,它将返回 B,而不是 P。如果单击粗体和斜体文本,它将返回 I 而不是 P。段落不是包含所有这些对象的最顶层元素,还是我对“最顶层”的定义与规范不同?

我在 Firefox 和 Chrome 上都试过了,结果都一样。

最佳答案

您误解了术语。

“最顶层”是指具有最高 z-index 的元素,或者在 View 中高于其他元素,而不是在层次结构方面。

关于javascript - 为什么 document.elementFromPoint 找不到最顶层的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24918945/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com