-
-
Save ststeiger/5d9af0cc4d9a953b66f5 to your computer and use it in GitHub Desktop.
This file contains 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 ($, document, undefined) { | |
$.extend({ | |
/** | |
* A static jQuery-method. | |
* @param {number} x The x-coordinate of the Point. | |
* @param {number} y The y-coordinate of the Point. | |
* @param {Element} until (optional) The element at which traversing should stop. Default is document.body | |
* @return {jQuery} A set of all elements visible at the given point. | |
*/ | |
elementsFromPoint: function(x,y, until) { | |
until || (until = document.body); // Stop traversing here | |
if (until instanceof $) until = until[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 | |
} | |
i = previousDisplay.length; | |
while ((d = previousDisplay.pop()) != null && i--) { | |
elements.get(i).style.display = d; // Restore the previous display-value | |
} | |
return $(elements); | |
} | |
}); | |
})(jQuery, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment