Created
February 9, 2020 10:24
-
-
Save Oluwa-nifemi/259c7e5745efb1b4819978ba2a8ba63b to your computer and use it in GitHub Desktop.
Recursive function to find an element's distance from the top of the page
This file contains 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
const getDistanceFromTop = (element,current = 0) => element.parentElement ? getDistanceFromTop(element.parentElement,element.offsetTop + current) : current; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment