Skip to content

Instantly share code, notes, and snippets.

@jovey-zheng
Last active August 2, 2017 06:52
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 jovey-zheng/56718e1318b882ec158a5cbeecd033a7 to your computer and use it in GitHub Desktop.
Save jovey-zheng/56718e1318b882ec158a5cbeecd033a7 to your computer and use it in GitHub Desktop.
Get element top in document
function getElementTop(elem) {
  var elemTop = elem.offsetTop;
  elem = elem.offsetParent;
  while (elem != null) {
    elemTop += elem.offsetTop;
    elem = elem.offsetParent;
  }
  return elemTop;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment