How To Detect Elements Overlapping (overlaying) Using JavaScript?
How to detect overlap HTML elements, using JavaScript? I have an item list (
- ). It slides up and down using JavaScript. When it slides down, depending on number of item, i
Solution 1:
function isObjOnObj(a,b){
var al = a.left;
var ar = a.left+a.width;
var bl = b.left;
var br = b.left+b.width;
var at = a.top;
var ab = a.top+a.height;
var bt = b.top;
var bb = b.top+b.height;
if(bl>ar || br<al){return false;}//overlap not possible
if(bt>ab || bb<at){return false;}//overlap not possible
if(bl>al && bl<ar){return true;}
if(br>al && br<ar){return true;}
if(bt>at && bt<ab){return true;}
if(bb>at && bb<ab){return true;}
return false;
}
Solution 2:
This feels like collision detection, and there's a solution just posted. Instead, I would suggest working out how many list items would be needed for a menu to overlap (i.e. 10), and hide the div
when those menus (with 10 li
) are selected.
Solution 3:
Why not just raise the z-index of your UL to be above the div at the bottom?
add:
#wrap {
z-index : 2;
position : relative;
}
Post a Comment for "How To Detect Elements Overlapping (overlaying) Using JavaScript?"