Last active
June 30, 2022 10:40
-
-
Save THEtheChad/4d7fb679f738f49dddcf58b87e582f8f to your computer and use it in GitHub Desktop.
Revisions
-
THEtheChad revised this gist
Jun 30, 2022 . 1 changed file with 9 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,15 @@ const offsetBase = document.createElement('div'); offsetBase.style.cssText = 'position:absolute;left:0;top:0'; document.body.appendChild(offsetBase); export default function getWindowPosition(node: Element) { const boundingRect = node.getBoundingClientRect(); const baseRect = offsetBase.getBoundingClientRect(); const left = boundingRect.left - baseRect.left; const top = boundingRect.top - baseRect.top; const width = boundingRect.right - boundingRect.left; const height = boundingRect.bottom - boundingRect.top; return { ...boundingRect, @@ -18,6 +18,6 @@ export default function getWindowPosition(node: Element){ width, height, right: left + width, bottom: top + height, }; } -
THEtheChad created this gist
Jun 30, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ const offsetBase = document.createElement('div'); offsetBase.style.cssText = 'position:absolute;left:0;top:0' document.body.appendChild(offsetBase); export default function getWindowPosition(node: Element){ const boundingRect = node.getBoundingClientRect(); const baseRect = offsetBase.getBoundingClientRect(); const left = boundingRect.left - baseRect.left const top = boundingRect.top - baseRect.top const width = boundingRect.right - boundingRect.left const height = boundingRect.bottom - boundingRect.top return { ...boundingRect, left, top, width, height, right: left + width, bottom: top + height } }