Last active
October 16, 2017 08:27
-
-
Save momin-riyadh/8bf2ae5cbf6130b105594d0da0960675 to your computer and use it in GitHub Desktop.
JavaScript Width change events
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>JavaScript Dynamically Width Change</title> | |
| </head> | |
| <body> | |
| <div id="header"></div> | |
| <script type="text/javascript"> | |
| window.addEventListener("resize", update); | |
| var x = document.getElementsByTagName(body); | |
| update(); | |
| function update() { | |
| if (document.body.innerWidth <= 600) { | |
| x.style.backgroundColor = "green", | |
| x.style.height = "100vh", | |
| x.style.color = "#ffffff", | |
| x.innerHTML = "<h2>Background has been changed!</h2>" | |
| } else { | |
| x.style.backgroundColor = "gray", | |
| x.style.height = "100vh" | |
| } | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment