JSCode
LoginResult JavaScript HTML CSS ALL Edit Share
$("#result").text(isOverlap("one","two")+","+isOverlap("one","three")+","+isOverlap("two","three"));
function isOverlap(idOne,idTwo){
var objOne=$("#"+idOne),
objTwo=$("#"+idTwo),
offsetOne = objOne.offset(),
offsetTwo = objTwo.offset(),
topOne=offsetOne.top,
topTwo=offsetTwo.top,
leftOne=offsetOne.left,
leftTwo=offsetTwo.left,
widthOne = objOne.width(),
widthTwo = objTwo.width(),
heightOne = objOne.height(),
heightTwo = objTwo.height();
var leftTop = leftTwo > leftOne && leftTwo && topTwo > topOne && topTwo rightTop = leftTwo+widthTwo > leftOne && leftTwo+widthTwo && topTwo > topOne && topTwo leftBottom = leftTwo > leftOne && leftTwo && topTwo+heightTwo > topOne && topTwo+heightTwo rightBottom = leftTwo+widthTwo > leftOne && leftTwo+widthTwo && topTwo+heightTwo > topOne && topTwo+heightTwo return leftTop || rightTop || leftBottom || rightBottom;
}
One
Two
Three
div{
width:200px;
height:200px;
background:#EEE;
}
#two{
position:absolute;
left:100px;
top:50px;
background:#F60;
}
DownLoad
JSCode demo One
Two
Three
Share link
Embed on your page
Share on Sina
Share on QQ