Skip to content

Instantly share code, notes, and snippets.

@kswedberg
Forked from padolsey/gist:272459
Created January 8, 2010 22:05
Show Gist options
  • Save kswedberg/272474 to your computer and use it in GitHub Desktop.
Save kswedberg/272474 to your computer and use it in GitHub Desktop.
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