Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dejurin
Last active July 17, 2018 19:32
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 dejurin/399aad0644f77f873a97b46534bc0791 to your computer and use it in GitHub Desktop.
Save dejurin/399aad0644f77f873a97b46534bc0791 to your computer and use it in GitHub Desktop.
function getOffset(el) {
if (typeof el !== 'undefined') {
if (el.getBoundingClientRect()) {
var box = el.getBoundingClientRect(),
body = document.body,
docElem = document.documentElement,
scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop,
clientTop = docElem.clientTop || body.clientTop || 0,
top = box.top + scrollTop - clientTop;
return Math.round(top);
} else {
var top = 0,
left = 0
while (el) {
top = top + parseInt(el.offsetTop)
el = el.offsetParent
}
return top
}
}
}
@dejurin
Copy link
Author

dejurin commented Jul 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment