Skip to content

Instantly share code, notes, and snippets.

@waaronking
Created June 9, 2014 20:41
Show Gist options
  • Save waaronking/0b61139bd13674b5ebfd to your computer and use it in GitHub Desktop.
Save waaronking/0b61139bd13674b5ebfd to your computer and use it in GitHub Desktop.
Find the offsetTop of any item by recursively looking at the parent element until parent offset is 0
/* Finds the total offset of an item inside a window */
var findOffsetTop = function(el) {
var offset = el.offsetTop;
if (el.parentNode.offsetTop !== 0) {
offset += findOffsetTop(el.parentNode);
}
return offset;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment