如果元素在另一个元素之上? [英] If element is over another element?

查看:139
本文介绍了如果元素在另一个元素之上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jQuery如何确定div one是否超过div two?不是,哪个z索引较高,但视觉上哪个div高于另一个div.

With jQuery how do i find out if div one is over div two? Not, which z-index is higher but what div is visually over the other 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>

推荐答案

您可以使用offset方法(这里)以获取文档边缘的空间.添加元素的宽度和高度,然后减去数字.

You can use the offset method (here) to get the space from the document edges. Add the width and height of the elements, and substract the numbers.

这篇关于如果元素在另一个元素之上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆