Skip to content

Instantly share code, notes, and snippets.

@caryfuk
caryfuk / getPosition.js
Last active June 25, 2021 16:24
alternative to Element.getBoundingClientRect() by https://github.com/kirupa
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 };