Skip to content

Instantly share code, notes, and snippets.

@webcyou
Created September 17, 2014 17:02
Show Gist options
  • Save webcyou/9e68327cb6bd2ea513ee to your computer and use it in GitHub Desktop.
Save webcyou/9e68327cb6bd2ea513ee to your computer and use it in GitHub Desktop.
get element position
var elm = document.getElementById("elm");
var getElmPosition = function(elm) {
var left = 0,
top = 0;
while(elm.parentNode) {
left += elm.offsetLeft;
top += elm.offsetTop;
elm = elm.parentNode;
}
return {"left" : left, "top" : top};
}
var elmPos = getElmPosition(elm);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment