Last active
June 25, 2021 16:24
-
-
Save caryfuk/3b7bb50831421f1873aa to your computer and use it in GitHub Desktop.
alternative to Element.getBoundingClientRect() by https://github.com/kirupa
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
function getPosition(elm) { | |
var xPos = 0, yPos = 0; | |
while(elm) { | |
xPos += (elm.offsetLeft - elm.scrollLeft + elm.clientLeft); | |
yPos += (elm.offsetTop - elm.scrollTop + elm.clientTop); | |
elm = elm.offsetParent; | |
} | |
return { x: xPos, y: yPos }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was trying to use this 'getBoundingClientRect'. but every time i get an error of null. I used this and it works! Wow... Great work 💯