Created
July 1, 2014 19:09
-
-
Save bchumney/8ddbcd0cdb2635f1b776 to your computer and use it in GitHub Desktop.
Get absolute screen coordinates
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 GetScreenCordinates(obj) { | |
var p = {}; | |
p.x = obj.offsetLeft; | |
p.y = obj.offsetTop; | |
while (obj.offsetParent) { | |
p.x = p.x + obj.offsetParent.offsetLeft; | |
p.y = p.y + obj.offsetParent.offsetTop; | |
if (obj == document.getElementsByTagName("body")[0]) { | |
break; | |
} | |
else { | |
obj = obj.offsetParent; | |
} | |
} | |
return p; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment