Skip to content

Instantly share code, notes, and snippets.

@bchumney
Created July 1, 2014 19:09
Show Gist options
  • Save bchumney/8ddbcd0cdb2635f1b776 to your computer and use it in GitHub Desktop.
Save bchumney/8ddbcd0cdb2635f1b776 to your computer and use it in GitHub Desktop.
Get absolute screen coordinates
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