Last active
August 29, 2015 14:15
-
-
Save ststeiger/71616b713c9450667e8a to your computer and use it in GitHub Desktop.
elementsFromPoint_SVG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function elementsFromPoint(x,y, until) | |
{ | |
// until || (until = document.body); // Stop traversing here | |
// if (until instanceof $) until = until[0]; | |
// http://stackoverflow.com/questions/1569775/how-do-i-find-the-dom-node-that-is-at-a-given-x-y-position-hit-test | |
if(!until) | |
{ | |
until = document.elementFromPoint(x,y); | |
while(until.ownerSVGElement) | |
{ | |
until = until.ownerSVGElement; | |
} | |
} | |
// console.log(until); | |
var j = 0; | |
var elements = [], previousDisplay = [], current, i, d, computedStyle = window.getComputedStyle; | |
while ( (current = document.elementFromPoint(x,y)) && current != null && current !== until) | |
{ | |
elements.push(current); | |
previousDisplay.push(computedStyle ? computedStyle(current)["display"] : current.currentStyle.display); | |
current.style.display = "none"; // Add display: none, to get to the underlying element | |
// ++j; if(j> 10) break; | |
} | |
i = previousDisplay.length; | |
while ((d = previousDisplay.pop()) != null && i--) | |
{ | |
//elements.get(i).style.display = d; // Restore the previous display-value | |
elements[i].style.display = d; // Restore the previous display-value | |
} | |
return elements; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment