Created
March 22, 2020 07:21
-
-
Save na0x2c6/c4c086ae68e19c1fc64d54ca8b1c8101 to your computer and use it in GitHub Desktop.
Calculating an element node 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
function calcOffset(elm: HTMLElement) { | |
const offset = { | |
top: 0, | |
left: 0, | |
} | |
do { | |
offset.top += elm.offsetTop || 0; | |
offset.left += elm.offsetLeft || 0; | |
} while((elm = elm.offsetParent as HTMLElement)); | |
return offset; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment