Skip to content

Instantly share code, notes, and snippets.

@lydell
Last active October 8, 2020 17:38
Show Gist options
  • Save lydell/47a3dd8caf394f4873abfe2139460599 to your computer and use it in GitHub Desktop.
Save lydell/47a3dd8caf394f4873abfe2139460599 to your computer and use it in GitHub Desktop.
Visualize .getBoundingClientRect()
function draw(rect) {
const div = document.createElement("div");
// Might be needed on crazy pages, but makes the console output for the div crazy large.
// div.style.all = "unset";
div.style.position = "absolute";
div.style.zIndex = "2147483647";
// At least _try_ to scroll along. Won’t work for inner scroll.
div.style.left = `${window.scrollX + rect.left}px`;
div.style.top = `${window.scrollY + rect.top}px`;
div.style.width = `${rect.width}px`;
div.style.height = `${rect.height}px`;
div.style.boxSizing = "border-box";
div.style.border = "1px solid magenta";
div.style.pointerEvents = "none";
document.documentElement.append(div);
return div;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment