Last active
October 8, 2020 17:38
-
-
Save lydell/47a3dd8caf394f4873abfe2139460599 to your computer and use it in GitHub Desktop.
Visualize .getBoundingClientRect()
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
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