Created
November 19, 2013 08:48
-
-
Save ifournight/7542277 to your computer and use it in GitHub Desktop.
DOM DIMENSIONS
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 getElementLeft(element) { | |
var actualLeft = element.offsetLeft; | |
var current = element.offsetParent; | |
while (current !== null) { | |
actualLeft += current.offsetLeft; | |
current = current.offsetParent; | |
} | |
return actualLeft; | |
} |
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 getElementTop(element) { | |
var actualTop = element.offsetTop; | |
var current = element.offsetParent; | |
while (current !== null) { | |
actualTop += current.offsetTop; | |
current = current.offsetParent; | |
} | |
return actualTop; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment