Last active
March 28, 2018 06:36
-
-
Save VoloshchenkoAl/a243d375648f1c3184447c18446fa5d8 to your computer and use it in GitHub Desktop.
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
/** | |
* 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