Having an arbitrary pair of colliding elements (by rects) in DOM tree, how to find which one of them is in front and which one is behind?(在DOM树中有一对任意的碰撞元素(通过rects),如何找到其中的哪个在前面,哪个在后面?)
Given el1
and el2
in DOM tree and knowing overlap points using el1.getBoundingClientRect()
and el2.getBoundingClientRect()
one can find the overlap rect.(给定DOM树中的el1
和el2
并使用el1.getBoundingClientRect()
和el2.getBoundingClientRect()
知道重叠点, el2.getBoundingClientRect()
可以找到重叠矩形。) However having (x,y) point inside overlap rect document.elementFromPoint(x,y)
returns just one element, which is in front of others at the given point.(但是,在重叠rect document.elementFromPoint(x,y)
有(x,y)点.elementFromPoint document.elementFromPoint(x,y)
仅返回一个元素,该元素在给定点位于其他元素的前面。) This element can be neither el1
nor el2
.(该元素不能是el1
或el2
。)
So if one needs to find if el1
is in front of el2
or vice versa, this approach does not work.(因此,如果需要确定el1
是否位于el2
,反之亦然,则此方法不起作用。)
ask by progmastery translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…