Created
March 5, 2021 09:10
-
-
Save captainbrosset/a394a25b27b19912edb7f69dfd5fc592 to your computer and use it in GitHub Desktop.
Code snippets for the "How we built the DevTools Tooltips" article
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 characters
// Get the coordinates of the element. | |
const rect = element.getBoundingClientRect(); | |
// Apply any offset that might be configured for it. | |
for (const {direction, size} of offsets) { | |
if (direction === Direction.Top) { | |
rect.y -= size; | |
rect.height += size; | |
} | |
if (direction === Direction.Right) { | |
rect.width += size; | |
} | |
if (direction === Direction.Bottom) { | |
rect.height += size; | |
} | |
if (direction === Direction.Left) { | |
rect.x -= size; | |
rect.width += size; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment