Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Dark Mode Toggler. #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions images/moon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/sun.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
<div class="upper-box">
<div class="upper-box-inital">
<header>IP Address Tracker</header>

<!-- Dark Mode Toggler -->
<label class="switch">
<input type="checkbox" id="darkModeToggle">
<span class="slider round"></span>
</label>

<form>
<input
type="text"
Expand Down
13 changes: 11 additions & 2 deletions scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ const fetchIPdata = function () {
.then((result) => {
renderData(result);
leafed(result);
}).catch((error) => {
})
.catch((error) => {
console.error(error); // Log the error for debugging
showToast(error.message);
});;
});
};
const renderData = function (result) {
ipAddressElement.innerText = result.ip;
Expand All @@ -102,3 +103,11 @@ const leafed = function (result) {
}).addTo(map);
marker.bindPopup("<b>You are Here!").openPopup();
};

// Function to toggle the dark mode
const toggleDarkMode = () => {
var element = document.getElementById("darkModeToggle");
element.addEventListener("change", () => {
document.body.classList.toggle("dark-mode");
});
};
85 changes: 85 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ body {
margin: 0%;
padding: 0%;
}

.dark-mode {
background-color: black;
color: white;
}

header {
font-size: 36px;
font-weight: bold;
Expand Down Expand Up @@ -145,3 +151,82 @@ input[type="submit"]:hover {
max-width: 50%;
}
}

/* Container for Dark Mode Toggler */
.switch {
position: absolute;
display: inline-block;
top: 10px;
right: 40px;
/* Change Height and width of the container here */
width: 100px;
height: 50px;
}


.switch input {
opacity: 0;
width: 0;
height: 0;
}

.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #eee;
transition: 0.4s;
border-radius: 24px;
}

.slider:before {
position: absolute;
content: "";
height: 50px;
width: 56px;
left: 6px;
background-image: url('./images/sun.svg');
background-repeat: no-repeat;
transition: 0.4s;
border-radius: 16px;
}


input:checked + .slider::before {
transform: translateX(40px);
background-image: url('./images/moon.svg');
width: 50px;
height: 45px;
bottom: 3px;
}

input:checked + .slider {
background-color: black;
}

/* Made the slider responsive */
@media (max-width: 600px) {
.switch {
top: 24px;
right: 10px;
width: 50px;
height: 30px;
}

.slider:before {
width: 30px;
height: 30px;
left: 2px;
}

input:checked + .slider::before {
transform: translateX(20px);
background-image: url('./images/moon.svg');
width: 40px;
height: 25px;
bottom: 3px;
}
}