Skip to content

Instantly share code, notes, and snippets.

@captainbrosset
Created March 5, 2021 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save captainbrosset/a394a25b27b19912edb7f69dfd5fc592 to your computer and use it in GitHub Desktop.
Save captainbrosset/a394a25b27b19912edb7f69dfd5fc592 to your computer and use it in GitHub Desktop.
Code snippets for the "How we built the DevTools Tooltips" article
// 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