Skip to content

Instantly share code, notes, and snippets.

@yeco
Created October 26, 2011 05:34
Show Gist options
  • Select an option

  • Save yeco/1315541 to your computer and use it in GitHub Desktop.

Select an option

Save yeco/1315541 to your computer and use it in GitHub Desktop.
getElementsInRegion.js
function getElementsInRegion(x, y, width, height) {
var elements = [],
expando = +new Date,
cx = x,
cy = y,
curEl;
height = y + height;
width = x + width;
while (cy += 5 < height) {
cx = x;
while (cx < width) {
curEl = document.elementFromPoint(cx, cy);
if ( curEl && !curEl[expando] ) {
curEl[expando] = new Number(0);
elements.push(curEl);
cx += curEl.offsetWidth;
} else {
cx += 5;
}
}
}
return elements;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment