From 7c91fdc20de9b355556fe7435ed6aaf4d75b5c15 Mon Sep 17 00:00:00 2001 From: VijaySamant4368 Date: Sun, 4 Aug 2024 20:07:41 +0530 Subject: [PATCH] Changed button --- Css-files/mode-toggler.css | 89 ++++++++++++++++++++++++++++++++++++++ Html-files/navbar.js | 13 +----- Images/moon.svg | 17 ++++++++ Images/sun.svg | 23 ++++++++++ index.html | 19 +++++--- 5 files changed, 144 insertions(+), 17 deletions(-) create mode 100644 Css-files/mode-toggler.css create mode 100644 Images/moon.svg create mode 100644 Images/sun.svg diff --git a/Css-files/mode-toggler.css b/Css-files/mode-toggler.css new file mode 100644 index 00000000..24ba661f --- /dev/null +++ b/Css-files/mode-toggler.css @@ -0,0 +1,89 @@ +.toggle-container { + transform: translate(-50%, -50%); + display: flex; + align-items: center; + justify-content: center; + right: -4px; + top: 15px; + /* position: fixed; */ + top: 40px; + right: 20%; + z-index: 100; + display: flex; + align-items: center; + border: none; + background-color: transparent; + width: 40px; + height: 20px; + margin-top: 10px; +} + + +/* Hidden Checkbox */ +.switch-checkbox { + display: none; +} + +.theme-switch { + position: relative; + width: 45px; + height: 30px; + background-color: #ccc; + border-radius: 20px; + cursor: pointer; + display: flex; + align-items: center; + justify-content: center; + padding: 0 5px; + box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); + transition: background-color 0.5s ease; +} + +.theme-switch .light-mode-icon, +.theme-switch .dark-mode-icon { + font-size: 19px; + position: absolute; + cursor: pointer; + top: 50%; + transform: translateY(-50%); + transition: opacity 0.5s ease, color 0.5s ease; +} + +.theme-switch .light-mode-icon { + color: #f39c12; +} + +.theme-switch .dark-mode-icon { + color: #bdc3c7; + opacity: 0; +} + +.toggle-button { + position: absolute; + top: 3px; + left: 3px; + width: 25px; + height: 25px; + background-color: #fff; + border-radius: 50%; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15); + transition: transform 0.5s ease, background-color 0.5s ease; +} + +/* Checkbox Checked State */ +.switch-checkbox:checked + .theme-switch { + background-color: #34495e; +} + +.switch-checkbox:checked + .theme-switch .light-mode-icon { + opacity: 0; +} + +.switch-checkbox:checked + .theme-switch .dark-mode-icon { + opacity: 1; +} + +.switch-checkbox:checked + .theme-switch .toggle-button { + transform: translateX(13px); + /* background-color: #34495e; */ +} diff --git a/Html-files/navbar.js b/Html-files/navbar.js index 745bc203..3d02f678 100644 --- a/Html-files/navbar.js +++ b/Html-files/navbar.js @@ -1,17 +1,8 @@ //Themechange icon toggling behaviour -let themeToggleIcon = document.getElementById("theme-toggle-icon"); -let themeToggleLogo = document.getElementById("theme-toggle-logo"); -themeToggleIcon.addEventListener("click", function () { +function toggleTheme() { document.body.classList.toggle("dark-theme"); document.body.classList.toggle(":root") - if (document.body.classList.contains("dark-theme")) { - themeToggleIcon.src = "../Images/navbar/sun.png"; - themeToggleLogo.src = "Images/logo/Logo-Dark.png"; - } else { - themeToggleIcon.src = "../Images/navbar/moon.png"; - themeToggleLogo.src="Images/logo/Logo-Light.png"; - } -}); +} //Services dropdown diff --git a/Images/moon.svg b/Images/moon.svg new file mode 100644 index 00000000..27b75366 --- /dev/null +++ b/Images/moon.svg @@ -0,0 +1,17 @@ + + + \ No newline at end of file diff --git a/Images/sun.svg b/Images/sun.svg new file mode 100644 index 00000000..8619f787 --- /dev/null +++ b/Images/sun.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/index.html b/index.html index b1637f61..66ee29f3 100644 --- a/index.html +++ b/index.html @@ -24,6 +24,7 @@ + @@ -164,12 +165,18 @@ -
- - theme toggler button - -
- + + +
+ + +
+