Created
June 18, 2020 19:11
-
-
Save astromac/5b0c237e854f791314af5721ad106ce5 to your computer and use it in GitHub Desktop.
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
/* Returns the absolute page position | |
* of a given element. | |
*/ | |
const absoluteElementPosition = node => { | |
if (isEmpty(node)) return null | |
let element = node | |
let left = 0 | |
let top = 0 | |
do { | |
top += element.offsetTop || 0 | |
left += element.offsetLeft || 0 | |
element = element.offsetParent | |
} while(element) | |
return { | |
top: top, | |
left: left | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment