Created
December 18, 2011 10:47
-
-
Save imikay/1493009 to your computer and use it in GitHub Desktop.
Get an element's position using JS
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
function getElementPosition(element) | |
{ | |
var x = element.offsetLeft; | |
var y = element.offsetTop; | |
var parent = element; | |
while (parent = parent.offsetParent) | |
{ | |
x += parent.offsetLeft; | |
y += parent.offsetTop; | |
} | |
return [x, y]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment