-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
273 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Block elements and variables | ||
|
||
const hourEl = document.querySelector(".hour"); | ||
const minuteEl = document.querySelector(".minute"); | ||
const secondEl = document.querySelector(".second"); | ||
const timeEl = document.querySelector(".time"); | ||
const dateEl = document.querySelector(".date"); | ||
const toggle = document.querySelector(".toggle"); | ||
|
||
const days = [ | ||
"Sunday", | ||
"Monday", | ||
"Tuesday", | ||
"Wednesday", | ||
"Thrusday", | ||
"Friday", | ||
"Saturday", | ||
]; | ||
|
||
const months = [ | ||
"Jan", | ||
"Feb", | ||
"Mar", | ||
"Apr", | ||
"May", | ||
"Jun", | ||
"Jul", | ||
"Aug", | ||
"Sep", | ||
"Oct", | ||
"Nov", | ||
"Dec", | ||
]; | ||
|
||
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"; | ||
} | ||
}); | ||
|
||
function setTime() { | ||
const time = new Date(); | ||
const month = time.getMonth(); | ||
const day = time.getDay(); | ||
const date = time.getDate(); | ||
const hours = time.getHours(); | ||
const hoursForClock = hours % 12; | ||
const minutes = time.getMinutes(); | ||
const seconds = time.getSeconds(); | ||
const ampm = hours >= 12 ? "PM" : "AM"; | ||
|
||
hourEl.style.transform = `translate(-50%, -100%) rotate(${scale( | ||
hoursForClock, | ||
0, | ||
11, | ||
0, | ||
360 | ||
)}deg)`; | ||
|
||
minuteEl.style.transform = `translate(-50%, -100%) rotate(${scale( | ||
minutes, | ||
0, | ||
59, | ||
0, | ||
360 | ||
)}deg)`; | ||
|
||
secondEl.style.transform = `translate(-50%, -100%) rotate(${scale( | ||
seconds, | ||
0, | ||
59, | ||
0, | ||
360 | ||
)}deg)`; | ||
|
||
timeEl.innerHTML = `${hoursForClock}:${ | ||
minutes < 10 ? `0${minutes}` : minutes | ||
} ${ampm}`; | ||
|
||
dateEl.innerHTML = `${days[day]}, ${months[month]}, <span class="circle">${date}</span>`; | ||
} | ||
|
||
// https://stackoverflow.com/questions/10756313/javascript-jquery-map-a-range-of-numbers-to-another-range-of-numbers | ||
|
||
const scale = (number, inMin, inMax, outMin, outMax) => { | ||
return ((number - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin; | ||
}; | ||
|
||
setTime(); | ||
|
||
setInterval(setTime, 1000); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!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" /> | ||
<link | ||
rel="stylesheet" | ||
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" | ||
integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==" | ||
crossorigin="anonymous" | ||
referrerpolicy="no-referrer" | ||
/> | ||
<link | ||
href="https://fonts.googleapis.com/css2?family=Heebo:wght@300&display=swap" | ||
rel="stylesheet" | ||
/> | ||
<link rel="stylesheet" href="./style.css" /> | ||
<title>Theme | Clock</title> | ||
</head> | ||
<body> | ||
<button class="toggle">Dark mode</button> | ||
<div class="clock-container"> | ||
<div class="clock"> | ||
<div class="niddle hour"></div> | ||
<div class="niddle minute"></div> | ||
<div class="niddle second"></div> | ||
<div class="center-point"></div> | ||
</div> | ||
|
||
<div class="time"></div> | ||
<div class="date"></div> | ||
</div> | ||
|
||
<script src="./app.js"></script> | ||
</body> | ||
</html> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
:root { | ||
--primary-color: #000; | ||
--secondary-color: #fff; | ||
} | ||
|
||
html.dark { | ||
--primary-color: #fff; | ||
--secondary-color: #333; | ||
} | ||
|
||
html { | ||
transition: all 0.5s ease-in; | ||
} | ||
|
||
html.dark { | ||
background-color: #111; | ||
color: var(--primary-color); | ||
} | ||
|
||
*::after, | ||
*::before { | ||
box-sizing: border-box; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
body { | ||
font-family: "Heebo", sans-serif; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100vh; | ||
overflow: hidden; | ||
margin: 0; | ||
} | ||
|
||
.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; | ||
} | ||
|
||
.clock-container { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
align-items: center; | ||
} | ||
|
||
.clock { | ||
position: relative; | ||
width: 200px; | ||
height: 200px; | ||
background-color: rgb(190, 154, 154); | ||
border-radius: 50%; | ||
border: 1px solid rgba(255, 0, 0, 0.671); | ||
} | ||
|
||
.niddle { | ||
background-color: var(--primary-color); | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
height: 65px; | ||
width: 3px; | ||
transform-origin: bottom center; | ||
transition: all 0.5s ease-in; | ||
} | ||
|
||
.niddle.hour { | ||
transform: translate(-50%, -100%) rotate(0deg); | ||
} | ||
|
||
.niddle.minute { | ||
transform: translate(-50%, -100%) rotate(0deg); | ||
height: 100px; | ||
} | ||
|
||
.niddle.second { | ||
transform: translate(-50%, -100%) rotate(0deg); | ||
height: 100px; | ||
background-color: #e74c3c; | ||
} | ||
|
||
.center-point { | ||
background-color: #e74c3c; | ||
width: 10px; | ||
height: 10px; | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
border-radius: 50%; | ||
} | ||
|
||
.center-point::after { | ||
content: ""; | ||
background-color: var(--primary-color); | ||
width: 5px; | ||
height: 5px; | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
border-radius: 50%; | ||
} | ||
|
||
.time { | ||
font-size: 60px; | ||
} | ||
|
||
.date { | ||
color: #aaa; | ||
font-size: 14px; | ||
letter-spacing: 0.3px; | ||
text-transform: uppercase; | ||
} | ||
|
||
.date .circle { | ||
background-color: var(--primary-color); | ||
color: var(--secondary-color); | ||
border-radius: 50%; | ||
width: 18px; | ||
height: 18px; | ||
display: inline-flex; | ||
align-items: center; | ||
justify-content: center; | ||
line-height: 18px; | ||
transition: all 0.5s ease-in; | ||
font-size: 12px; | ||
} |