Skip to content

Commit 60ef880

Browse files
committed
css clock done
1 parent 45e3d1d commit 60ef880

File tree

1 file changed

+86
-60
lines changed

1 file changed

+86
-60
lines changed
Lines changed: 86 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,99 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
4-
<meta charset="UTF-8">
5-
<title>JS + CSS Clock</title>
5+
<meta charset="UTF-8">
6+
<title>JS + CSS Clock</title>
67
</head>
8+
79
<body>
810

911

1012
<div class="clock">
11-
<div class="clock-face">
12-
<div class="hand hour-hand"></div>
13-
<div class="hand min-hand"></div>
14-
<div class="hand second-hand"></div>
15-
</div>
13+
<div class="clock-face">
14+
<div class="hand hour-hand"></div>
15+
<div class="hand min-hand"></div>
16+
<div class="hand second-hand"></div>
17+
</div>
1618
</div>
1719

1820

19-
<style>
20-
html {
21-
background:#018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
22-
background-size:cover;
23-
font-family:'helvetica neue';
24-
text-align: center;
25-
font-size: 10px;
26-
}
27-
28-
body {
29-
font-size: 2rem;
30-
display:flex;
31-
flex:1;
32-
min-height: 100vh;
33-
align-items: center;
34-
}
35-
36-
.clock {
37-
width: 30rem;
38-
height: 30rem;
39-
border:20px solid white;
40-
border-radius:50%;
41-
margin:50px auto;
42-
position: relative;
43-
padding:2rem;
44-
box-shadow:
45-
0 0 0 4px rgba(0,0,0,0.1),
46-
inset 0 0 0 3px #EFEFEF,
47-
inset 0 0 10px black,
48-
0 0 10px rgba(0,0,0,0.2);
49-
}
50-
51-
.clock-face {
52-
position: relative;
53-
width: 100%;
54-
height: 100%;
55-
transform: translateY(-3px); /* account for the height of the clock hands */
56-
}
57-
58-
.hand {
59-
width:50%;
60-
height:6px;
61-
background:black;
62-
position: absolute;
63-
top:50%;
64-
}
65-
66-
</style>
67-
68-
<script>
69-
70-
71-
</script>
21+
<style>
22+
html {
23+
background: #018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
24+
background-size: cover;
25+
font-family: 'helvetica neue';
26+
text-align: center;
27+
font-size: 10px;
28+
}
29+
30+
body {
31+
font-size: 2rem;
32+
display: flex;
33+
flex: 1;
34+
min-height: 100vh;
35+
align-items: center;
36+
}
37+
38+
.clock {
39+
width: 30rem;
40+
height: 30rem;
41+
border: 20px solid white;
42+
border-radius: 50%;
43+
margin: 50px auto;
44+
position: relative;
45+
padding: 2rem;
46+
box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.1), inset 0 0 0 3px #EFEFEF, inset 0 0 10px black, 0 0 10px rgba(0, 0, 0, 0.2);
47+
}
48+
49+
.clock-face {
50+
position: relative;
51+
width: 100%;
52+
height: 100%;
53+
transform: translateY(-3px);
54+
/* account for the height of the clock hands */
55+
}
56+
57+
.hand {
58+
width: 50%;
59+
height: 6px;
60+
background: black;
61+
position: absolute;
62+
top: 50%;
63+
transform-origin: 100%; //przesuwa wskazówka do środka, dzięki czemu obraca się ona na środku okręgu
64+
transform: rotate(90deg); //ustawia ja na godzinę 12
65+
transition: all 0.05s;
66+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1); //efekt tykania
67+
}
68+
</style>
69+
70+
71+
<script>
72+
const hourHand = document.querySelector('.hour-hand');
73+
const minsHand = document.querySelector('.min-hand');
74+
const secondHand = document.querySelector('.second-hand');
75+
76+
function setDate() {
77+
const now = new Date();
78+
79+
const hour = now.getHours();
80+
const hourDegrees = ((hour / 12) * 360) + 90; // odpowiada za obrót wskazówek wokól osi, zgodnie z licznikiem godzin
81+
hourHand.style.transform = `rotate(${hourDegrees}deg)`; // ustawienie stylu
82+
83+
const mins = now.getMinutes();
84+
const minsDegrees = ((mins / 60) * 360) + 90; // odpowiada za obrót wskazówek wokól osi, zgodnie z licznikiem minut
85+
minsHand.style.transform = `rotate(${minsDegrees}deg)`;
86+
87+
const seconds = now.getSeconds();
88+
const secondsDegrees = ((seconds / 60) * 360) + 90; // odpowiada za obrót wskazówek wokól osi, zgodnie z licznikiem sekund
89+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
90+
91+
console.log(seconds);
92+
93+
}
94+
setInterval(setDate, 1000);
95+
setDate();
96+
</script>
7297
</body>
98+
7399
</html>

0 commit comments

Comments
 (0)