A Pen by David Sairai on CodePen.
Created
July 17, 2019 14:55
-
-
Save DavidSairai/7da0ad0951fa4ad96dba74aa87f70bda to your computer and use it in GitHub Desktop.
Dark -Light Mode Switcher
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
<body id="body" class="dark-mode"> | |
<h1>Dark/Light Mode Switcher</h1> | |
<button type="button" name="dark_light" onclick="toggleDarkLight()" title="Toggle dark/light mode">🌛</button> | |
<p>Just press the button above to toggle!</p> |
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
function toggleDarkLight() { | |
var body = document.getElementById("body"); | |
var currentClass = body.className; | |
body.className = currentClass == "dark-mode" ? "light-mode" : "dark-mode"; | |
} |
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
$dark-color: #111; | |
$light-color: #eee; | |
body.dark-mode { | |
background-color: $dark-color; | |
color: $light-color; | |
a { | |
color: $dark-color; | |
} | |
button { | |
background-color: $light-color; | |
color: $dark-color; | |
} | |
} | |
body.light-mode { | |
background-color: $light-color; | |
color: $dark-color; | |
a { | |
color: $dark-color; | |
} | |
button { | |
background-color: $dark-color; | |
color: $light-color; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment