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){returnfalse;}//overlap not possibleif(bt>ab || bb<at){returnfalse;}//overlap not possibleif(bl>al && bl<ar){returntrue;}
if(br>al && br<ar){returntrue;}
if(bt>at && bt<ab){returntrue;}
if(bb>at && bb<ab){returntrue;}
returnfalse;
}
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.
Post a Comment for "How To Detect Elements Overlapping (overlaying) Using Javascript?"