Skip to content

Instantly share code, notes, and snippets.

@alexcambose
Created February 7, 2019 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexcambose/830e33a8f360e0b4a477e6e8f64fcd5a to your computer and use it in GitHub Desktop.
Save alexcambose/830e33a8f360e0b4a477e6e8f64fcd5a to your computer and use it in GitHub Desktop.
Offset
const getOffsetTop = element => {
let offsetTop = 0;
while(element) {
offsetTop += element.offsetTop;
element = element.offsetParent;
}
return offsetTop;
}
// calling
const someElement = document.getElementById('someElementId');
const X = getOffsetTop(someElement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment