Created
September 17, 2014 17:02
-
-
Save webcyou/9e68327cb6bd2ea513ee to your computer and use it in GitHub Desktop.
get element position
This file contains 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
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