Last active
May 10, 2022 02:43
-
-
Save joshuacerbito/8eb4d6240de141956e15b885be9b195e to your computer and use it in GitHub Desktop.
Get an Element's Offset relative to the document
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 getElementOffset = el => { | |
const rect = el.getBoundingClientRect(), | |
scrollLeft = window.scrollX || document.documentElement.scrollLeft, | |
scrollTop = window.scrollY || document.documentElement.scrollTop; | |
return { | |
top: rect.top + scrollTop, | |
left: rect.left + scrollLeft | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment