Skip to content

Instantly share code, notes, and snippets.

@VoloshchenkoAl
Last active March 28, 2018 06:36
Show Gist options
  • Save VoloshchenkoAl/a243d375648f1c3184447c18446fa5d8 to your computer and use it in GitHub Desktop.
Save VoloshchenkoAl/a243d375648f1c3184447c18446fa5d8 to your computer and use it in GitHub Desktop.
/**
* relates an element's border box to the document origin
*
* @param {DOMObject} current element
* @return {Object} top and left cooridanets of element relative to origin document
*/
function offset(element) {
const rect = element.getBoundingClientRect();
const win = element.ownerDocument.defaultView;
return {
top: rect.top + win.pageYOffset,
left: rect.left + win.pageXOffset;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment