Created
January 26, 2016 14:26
-
-
Save wakumaku/713702a8319e584fb319 to your computer and use it in GitHub Desktop.
Returns the relative position of an element in the page
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
// 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