Created
December 28, 2011 16:35
-
-
Save larscwallin/1528591 to your computer and use it in GitHub Desktop.
jquery.elementFromPoint
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 ($){ | |
var check=false, isRelative=true; | |
$.elementFromPoint = function(x,y) | |
{ | |
if(!document.elementFromPoint) return null; | |
if(!check) | |
{ | |
var sl; | |
if((sl = $(document).scrollTop()) >0) | |
{ | |
isRelative = (document.elementFromPoint(0, sl + $(window).height() -1) == null); | |
} | |
else if((sl = $(document).scrollLeft()) >0) | |
{ | |
isRelative = (document.elementFromPoint(sl + $(window).width() -1, 0) == null); | |
} | |
check = (sl>0); | |
} | |
if(!isRelative) | |
{ | |
x += $(document).scrollLeft(); | |
y += $(document).scrollTop(); | |
} | |
return document.elementFromPoint(x,y); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Beware, in IE 8, you won't get == null, event if elementFromPoint is operating outside the window area, for isRelative will be incorrect.