Created
June 1, 2021 15:14
-
-
Save cwood821/611269b602697ebba8dd8eb2b10a5897 to your computer and use it in GitHub Desktop.
Show width on page resize
This file contains 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
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