Skip to content

Instantly share code, notes, and snippets.

@ifournight
Created November 19, 2013 08:48
Show Gist options
  • Save ifournight/7542277 to your computer and use it in GitHub Desktop.
Save ifournight/7542277 to your computer and use it in GitHub Desktop.
DOM DIMENSIONS
function getElementLeft(element) {
var actualLeft = element.offsetLeft;
var current = element.offsetParent;
while (current !== null) {
actualLeft += current.offsetLeft;
current = current.offsetParent;
}
return actualLeft;
}
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