Skip to content

@Pichan /gist:5498404
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Returns all elements under the position [clientX,clientY] in an array
/**
* Returns all elements under the position [clientX,clientY] in an array
*
* @param int X position relative to the viewport
* @param int Y position relative to the viewport
* @param domElm The root element at which to stop looping. Defaults to document.body
*
* @returns array List of elements under the given position
*/
document.elementsFromPoint = function(clientX,clientY,root) {
// root defaults to document.body
if (root == undefined)
root = document.body;
var elements = [];
var elm;
while (elm = document.elementFromPoint(clientX,clientY)) {
if (elm == root)
break;
elements.push(elm);
// store the original display style and hide the current layer by setting display to none
elm.oldDisplay = elm.style.display;
elm.style.display = 'none';
}
// restore the original display values
for (var i = 0; i < elements.length; i++) {
elements[i].style.display = elements[i].oldDisplay;
delete elements[i].oldDisplay;
}
return elements;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.