GitHub 6219★

Get the position of an element relative to the document

JavaScript version

const getPosition = (ele) => ((r = ele.getBoundingClientRect()), { left: r.left + window.scrollX, top: r.top + window.scrollY });

Example

getPosition(document.body); // { left: 0, top: 0 }
Follow me on and to get more useful contents.