Skip to content

Instantly share code, notes, and snippets.

@astromac
Created June 18, 2020 19:11
Show Gist options
  • Save astromac/5b0c237e854f791314af5721ad106ce5 to your computer and use it in GitHub Desktop.
Save astromac/5b0c237e854f791314af5721ad106ce5 to your computer and use it in GitHub Desktop.
/* 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