Skip to content

Instantly share code, notes, and snippets.

@cwood821
Created June 1, 2021 15:14
Show Gist options
  • Save cwood821/611269b602697ebba8dd8eb2b10a5897 to your computer and use it in GitHub Desktop.
Save cwood821/611269b602697ebba8dd8eb2b10a5897 to your computer and use it in GitHub Desktop.
Show width on page resize
window.addEventListener("resize", () => {
try {
let el = document.querySelector("#wsize");
if (!el) {
let body = document.querySelector("body");
let created = document.createElement("div");
created.setAttribute("ID", "wsize");
created.style = `z-index: 101; color: #000; position: fixed; top: 10px; right: 20px; font-size: 3em; font-weight: bold;`;
created.innerText = window.innerWidth;
body.appendChild(created)
} else {
el.innerText = window.innerWidth;
}
} catch (_) {}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment