Created
June 9, 2014 20:41
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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