Skip to content

Commit 205f085

Browse files
author
Fred Valle
committed
js clock with image background
1 parent 6586c77 commit 205f085

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

JS_Clock/alvalle09/css/style.css

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
html {
2+
background: #018ded url(http://unsplash.it/1500/1000?image=881&blur=1);
3+
background-size: cover;
4+
font-family: "helvetica neue";
5+
text-align: center;
6+
font-size: 10px;
7+
}
8+
9+
body {
10+
margin: 0;
11+
font-size: 2rem;
12+
display: flex;
13+
flex: 1;
14+
min-height: 100vh;
15+
align-items: center;
16+
}
17+
18+
.clock {
19+
width: 30rem;
20+
height: 30rem;
21+
border: 20px solid white;
22+
border-radius: 10%;
23+
margin: 50px auto;
24+
position: relative;
25+
padding: 2rem;
26+
box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.1), inset 0 0 0 3px #efefef,
27+
inset 0 0 10px black, 0 0 10px rgba(0, 0, 0, 0.2);
28+
}
29+
30+
.clock-face {
31+
position: relative;
32+
width: 100%;
33+
height: 100%;
34+
transform: translateY(-3px); /* account for the height of the clock hands */
35+
}
36+
37+
.hand {
38+
width: 50%;
39+
height: 6px;
40+
background: black;
41+
position: absolute;
42+
top: 50%;
43+
transform-origin: 100%;
44+
transform: rotate(90deg);
45+
}
46+
47+
.hour-hand {
48+
border: #018ded solid;
49+
width: 50%;
50+
height: 10px;
51+
background: rgb(66, 173, 119);
52+
position: absolute;
53+
top: 50%;
54+
transform-origin: 100%;
55+
transform: rotate(90deg);
56+
}
57+
58+
.min-hand {
59+
border: #efefef solid;
60+
width: 50%;
61+
height: 7px;
62+
background: rgb(135, 68, 223);
63+
position: absolute;
64+
top: 50%;
65+
transform-origin: 100%;
66+
transform: rotate(90deg);
67+
}
68+
69+
.second-hand {
70+
background: blue;
71+
width: 50%;
72+
height: 6px;
73+
background: blue;
74+
position: absolute;
75+
top: 50%;
76+
transform-origin: 100%;
77+
transform: rotate(90deg);
78+
transition: all 0.5s;
79+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
80+
}

JS_Clock/alvalle09/index.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>JS + CSS Clock</title>
6+
<link rel="stylesheet" href="css/style.css">
7+
</head>
8+
<body>
9+
10+
11+
<div class="clock">
12+
<div class="clock-face">
13+
<div class="hour-hand">
14+
Hour
15+
</div>
16+
<div class="min-hand">
17+
Minute
18+
</div>
19+
<div class="second-hand"></div>
20+
</div>
21+
</div>
22+
23+
<script src="js/script.js"></script>
24+
25+
</body>
26+
27+
28+
29+
</html>

JS_Clock/alvalle09/js/script.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const secondHand = document.querySelector('.second-hand');
2+
const minsHand = document.querySelector('.min-hand');
3+
const hourHand = document.querySelector('.hour-hand');
4+
5+
6+
function setDate() {
7+
const now = new Date();
8+
9+
const seconds = now.getSeconds();
10+
const secondsDegrees = ((seconds / 60) * 360) + 90;
11+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
12+
13+
const mins = now.getMinutes();
14+
const minsDegrees = ((mins / 60) * 360) + ((seconds/60)*6) + 90;
15+
minsHand.style.transform = `rotate(${minsDegrees}deg)`;
16+
17+
const hour = now.getHours();
18+
const hourDegrees = ((hour / 12) * 360) + ((mins/60)*30) + 90;
19+
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
20+
}
21+
22+
setInterval(setDate, 1000);
23+
24+
setDate();
25+
26+

0 commit comments

Comments
 (0)