Created
February 7, 2019 08:39
-
-
Save alexcambose/830e33a8f360e0b4a477e6e8f64fcd5a to your computer and use it in GitHub Desktop.
Offset
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
const getOffsetTop = element => { | |
let offsetTop = 0; | |
while(element) { | |
offsetTop += element.offsetTop; | |
element = element.offsetParent; | |
} | |
return offsetTop; | |
} | |
// calling | |
const someElement = document.getElementById('someElementId'); | |
const X = getOffsetTop(someElement); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment