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

Dark & Light Mode added to existing Analog Clock #612

Closed
wants to merge 4 commits into from
Closed
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
110 changes: 66 additions & 44 deletions Javascript/Analog Clock/index.css
Original file line number Diff line number Diff line change
@@ -1,65 +1,87 @@
.container{

/* border: 5px solid green; */

height: 40vw;
width: 40vw;
position: relative;
background: url(clock.png) no-repeat center center/cover;
margin: auto;

:root {
--primary-color: #000;
--secondary-color: #fff;
}

#hour,#minute,#second{

position: absolute;
background-color: black;
height: 30px;
width: 30px;
border-radius: 10px;
transform-origin: bottom;
.container {
/* border: 5px solid green; */

height: 40vw;
width: 40vw;
position: relative;
background: url(clock.png) no-repeat center center/cover;
margin: auto;
}

#hour{
#hour,
#minute,
#second {
position: absolute;
background-color: black;
height: 30px;
width: 30px;
border-radius: 10px;
transform-origin: bottom;
}

/* background-color: black;
#hour {
/* background-color: black;
height: 11vw;
margin: 24% auto;
width: 2vw;
border-radius: 2rem;
position: absolute; */

height: 21%;
width: 2%;
top: 30%;
/* margin-top: 24%; */
/* z-index: 1;*/

left: 48.8%;
/* display: none; */
height: 21%;
width: 2%;
top: 30%;
/* margin-top: 24%; */
/* z-index: 1;*/

left: 48.8%;
/* display: none; */
}

#minute{
#minute {
height: 30%;
width: 1.6%;
top: 21%;
/* margin-top: 24%; */
left: 49%;
opacity: 0.8;
/* display: none; */
}

height: 30%;
width: 1.6%;
top: 21%;
/* margin-top: 24%; */
left: 49%;
opacity: 0.8;
/* display: none; */
#second {
height: 38%;
width: 1%;
top: 12%;
/* margin-top: 24%; */
left: 49.3%;
/* display: none; */
}

html.dark {
--primary-color: #fff;
--secondary-color: #333;
}

#second{
html.dark {
background-color: #111;
color: var(--primary-color);
}

height: 38%;
width: 1%;
top: 12%;
/* margin-top: 24%; */
left: 49.3%;
/* display: none; */
.toggle {
cursor: pointer;
background-color: var(--primary-color);
color: var(--secondary-color);
border: 0;
border-radius: 4px;
padding: 8px 12px;
position: absolute;
top: 100px;
}

}
.toggle:focus {
outline: none;
}
35 changes: 20 additions & 15 deletions Javascript/Analog Clock/index.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Analog Clock</title>
<link rel="shortcut icon" href="cg.png" type="image/x-icon">
<link rel="stylesheet" href="index.css">
<script src="index.js"></script>
</head>
<link rel="shortcut icon" href="cg.png" type="image/x-icon" />
<link rel="stylesheet" href="index.css" />
</head>

<body>
<button
class="toggle"
style="margin-left: 80%; display: block; margin-top: -50px"
>
Dark mode
</button>

<body>
<div class="container">
<div id="hour"></div>
<div id="minute"></div>
<div id="second"></div>
<div id="hour"></div>
<div id="minute"></div>
<div id="second"></div>
</div>
</body>

</html>
<script src="index.js"></script>
</body>
</html>
34 changes: 23 additions & 11 deletions Javascript/Analog Clock/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
const toggle = document.querySelector(".toggle");
toggle.addEventListener("click", (e) => {
const html = document.querySelector("html");
if (html.classList.contains("dark")) {
html.classList.remove("dark");
e.target.innerHTML = "Dark mode";
} else {
html.classList.add("dark");
e.target.innerHTML = "Light mode";
}
});

setInterval(() => {
d = new Date();
htime = d.getHours();
mtime = d.getMinutes();
stime = d.getSeconds();
d = new Date();
htime = d.getHours();
mtime = d.getMinutes();
stime = d.getSeconds();

hrotation = 30 * htime + mtime / 2;
mrotation = 6 * mtime;
srotation = 6 * stime;
hrotation = 30 * htime + mtime / 2;
mrotation = 6 * mtime;
srotation = 6 * stime;

hour.style.transform = `rotate(${hrotation}deg)`;
minute.style.transform = `rotate(${mrotation}deg)`;
second.style.transform = `rotate(${srotation}deg)`;
}, 1000);
hour.style.transform = `rotate(${hrotation}deg)`;
minute.style.transform = `rotate(${mrotation}deg)`;
second.style.transform = `rotate(${srotation}deg)`;
}, 1000);