This is a solution to the problem, as described in the comments (although not on the current issue). I think it would be much faster to use elementFromPoint to check the area in which you want to place a fixed position element, and only worry about the elements in that area. Example:
http://jsfiddle.net/pQgwE/4/
Basically, just set the minimum possible size of the element you are looking for and scan the entire area that your new fixed position element wants to occupy. Create a list of unique elements found there, and only worry about checking the style of these elements.
Note that this method assumes that the item you are looking for has the highest z index (which seems like a reasonable assumption for a fixed position). If this is not enough, then this can be adjusted to hide (or assign a minimum z-index) to each element after it is detected and check the point again until nothing is found (if necessary), and then restore them later. This must happen so quickly as to be inconspicuous.
HTML:
<div style="position:fixed; left: 10px; top: 10px; background-color: #000000; color: #FF0000;">I Am Fixed</div> <div id="floater">OccupyJSFiddle!<br>for two lines</div>
JS:
var w = $(window).width(), h=$(window).height(), minWidth=10, minHeight=10, x,y; var newFloat = $('#floater'), maxHeight = newFloat.height(), el, uniqueEls=[], i; for (x=0;x<w;x+=minWidth) { for (y=0;y<h&& y<maxHeight;y+=minHeight) { el = document.elementFromPoint(x,y); if (el && $.inArray(el,uniqueEls)<0) { uniqueEls.push(el); } } }
Jamie Treworgy Jan 05 2018-12-12T00: 00Z
source share