Skip to content

Instantly share code, notes, and snippets.

@wakumaku
Created January 26, 2016 14:26
Show Gist options
  • Save wakumaku/713702a8319e584fb319 to your computer and use it in GitHub Desktop.
Save wakumaku/713702a8319e584fb319 to your computer and use it in GitHub Desktop.
Returns the relative position of an element in the page
// http://stackoverflow.com/questions/288699/get-the-position-of-a-div-span-tag
function getPos(el) {
// yay readability
for (var lx=0, ly=0;
el != null;
lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
return {x: lx,y: ly};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment