Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
56 changes: 56 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.tailwindcss.com"></script>
<script src="./tailwind.config.js"></script>
<title>Dark-Mode-Toggle-Codante</title>
</head>
<body
class="bg-zinc-900 dark:bg-zinc-100 h-screen flex items-center justify-center transition-colors duration-300"
>
<label
for="check"
class="cursor-pointer relative bg-zinc-700 dark:bg-zinc-300 w-20 h-10 rounded-full shadow-inner"
>
<input
onclick="themeToggle()"
type="checkbox"
id="check"
class="sr-only peer"
/>
<span
class="w-2/5 h-4/5 bg-zinc-800 absolute rounded-full left-1 top-1 peer-checked:bg-zinc-100 peer-checked:left-11 transition-all duration-500 peer-checked:drop-shadow-xl"
>
<svg
id="moon"
class="absolute dark:invisible "
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="white"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"
/>
</svg>
<svg
id="sun"
id="span"
class="absolute invisible dark:visible transform rotate-180"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="#EAB308"
>
<path
d="M12 2.25a.75.75 0 01.75.75v2.25a.75.75 0 01-1.5 0V3a.75.75 0 01.75-.75zM7.5 12a4.5 4.5 0 119 0 4.5 4.5 0 01-9 0zM18.894 6.166a.75.75 0 00-1.06-1.06l-1.591 1.59a.75.75 0 101.06 1.061l1.591-1.59zM21.75 12a.75.75 0 01-.75.75h-2.25a.75.75 0 010-1.5H21a.75.75 0 01.75.75zM17.834 18.894a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 10-1.061 1.06l1.59 1.591zM12 18a.75.75 0 01.75.75V21a.75.75 0 01-1.5 0v-2.25A.75.75 0 0112 18zM7.758 17.303a.75.75 0 00-1.061-1.06l-1.591 1.59a.75.75 0 001.06 1.061l1.591-1.59zM6 12a.75.75 0 01-.75.75H3a.75.75 0 010-1.5h2.25A.75.75 0 016 12zM6.697 7.757a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 00-1.061 1.06l1.59 1.591z"
/>
</svg>
</span>
</label>
</body>
</html>
17 changes: 17 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
tailwind.config = {
darkMode: 'class',
};

function themeToggle(event) {
const moon = document.querySelector('#moon');
const sun = document.querySelector('#sun');
const audio = new Audio('https://www.fesliyanstudios.com/play-mp3/387');
audio.play();
moon.classList.add('animate-spin');
sun.classList.add('animate-spin');
setTimeout(() => {
document.documentElement.classList.toggle('dark');
moon.classList.remove('animate-spin');
sun.classList.remove('animate-spin');
}, 300);
}