2012-01-15 55 views
11

使用jQuery我如何知道div one是否在div two?不是,哪个z-index更高,但是div在视觉上是否在其他div上。如果元素超过另一个元素?

<style type='text/css'> 
    #one { 
    position:absolute; top:0; left:0; width:100px; height:100px; background-color:red; z-index:2; 
    } 
    #two { 
    position:absolute; top:0; left:0; width:100px; height:100px; background-color:green; z-index:1; 
    } 
    </style>  
    <div id='one'></div> 
     <div id='two'></div> 
+0

这可能是一个重复:http://stackoverflow.com/questions/8628368/how-do-i-implement-collision-detection-between-a-set-of-div-elements – 2012-12-29 05:30:21

回答

13

可以使用offset方法(here)从文档边缘得到的空间。添加元素的宽度和高度,并减去数字。

Offset and width for div's

相关问题