Switch between Light/Dark mode with the toggle.
Created
March 4, 2020 16:27
-
-
Save mdsabir07/48c2c80d47365c359874d0cbd75003ed to your computer and use it in GitHub Desktop.
Light/Dark Mode toggle Navigation Bar
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
<div class="theme-switch"> | |
<div class="switch"></div> | |
</div> | |
<div class="navigation"> | |
<ul> | |
<a href="http://www.sashatran.com/" class="active" target="_blank">Home</a> | |
<a href="https://codepen.io/sashatran/" target="_blank">About</a> | |
<a href="https://instagram.com/sasha.codes/" target="_blank">Instagram</a> | |
<a href="https://twitter.com/sa_sha26" target="_blank">Twitter</a> | |
</ul> | |
</div> |
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
$(".theme-switch").on("click", () => { | |
$("body").toggleClass("light-theme"); | |
}); |
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> |
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
:root { | |
--background: #000; | |
--text: #FFF; | |
--highlight: #FF1EAD; | |
} | |
@import url('https://fonts.googleapis.com/css?family=Oswald'); | |
body { | |
background: var(--background); | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
height: 100vh; | |
overflow: hidden; | |
transition: 0.5s background ease; | |
} | |
.theme-switch { | |
--background: #FFF; | |
--text: #000; | |
color: var(--text); | |
width: 70px; | |
height: 30px; | |
background: var(--highlight); | |
border-radius: 50px; | |
position: relative; | |
.switch { | |
background: white; | |
width: 24px; | |
height: 24px; | |
background: var(--background); | |
border-radius: 100%; | |
position: absolute; | |
top: 3px; | |
left: 4px; | |
transition: 0.5s all ease; | |
} | |
} | |
.light-theme { | |
--background: #FFF; | |
--text: #000; | |
background: var(--background); | |
.theme-switch { | |
background: var(--text); | |
.switch { | |
transform: translateX(37px); | |
} | |
} | |
a { | |
color: var(--text); | |
} | |
} | |
.navigation { | |
display: flex; | |
justify-content: center; | |
} | |
ul { | |
display: flex; | |
list-style-type: none; | |
a { | |
margin: 10px; | |
position: relative; | |
color: var(--text); | |
font-family: 'Oswald', sans-serif; | |
font-size: 20px; | |
text-transform: uppercase; | |
text-decoration: none; | |
&:before { | |
position: absolute; | |
bottom: -2px; | |
content: ''; | |
width: 100%; | |
height: 3px; | |
background: var(--highlight); | |
transform: translateX(-100%); | |
opacity: 0; | |
} | |
&:hover { | |
&:before { | |
opacity: 1; | |
transition: 0.5s transform ease, 0.8s opacity ease; | |
transform: translateX(0); | |
} | |
} | |
} | |
.active { | |
color: var(--highlight); | |
&:hover { | |
&:before { | |
opacity: 0; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment