-
-
Save handleman/e2b8cd1e54d0b5407fbe7e56f2e37001 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