Skip to content

Instantly share code, notes, and snippets.

@DavidSairai
Created July 17, 2019 14:55
Show Gist options
  • Save DavidSairai/7da0ad0951fa4ad96dba74aa87f70bda to your computer and use it in GitHub Desktop.
Save DavidSairai/7da0ad0951fa4ad96dba74aa87f70bda to your computer and use it in GitHub Desktop.
Dark -Light Mode Switcher
<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>
function toggleDarkLight() {
var body = document.getElementById("body");
var currentClass = body.className;
body.className = currentClass == "dark-mode" ? "light-mode" : "dark-mode";
}
$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