|
1 | 1 | <!DOCTYPE html>
|
2 | 2 | <html lang="en">
|
3 | 3 | <head>
|
4 |
| - <meta charset="UTF-8"> |
5 |
| - <title>JS + CSS Clock</title> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <title>JS + CSS Clock</title> |
6 | 6 | </head>
|
7 | 7 | <body>
|
8 | 8 |
|
9 | 9 |
|
10 |
| - <div class="clock"> |
| 10 | + <div class="clock"> |
11 | 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> |
| 12 | + <div class="hand hour-hand"></div> |
| 13 | + <div class="hand min-hand"></div> |
| 14 | + <div class="hand second-hand"></div> |
15 | 15 | </div>
|
16 |
| - </div> |
| 16 | + </div> |
17 | 17 |
|
18 | 18 |
|
19 |
| - <style> |
20 |
| - html { |
| 19 | + <style> |
| 20 | + html { |
21 | 21 | background:#018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
|
22 | 22 | background-size:cover;
|
23 | 23 | font-family:'helvetica neue';
|
24 | 24 | text-align: center;
|
25 | 25 | font-size: 10px;
|
26 |
| - } |
| 26 | + } |
27 | 27 |
|
28 |
| - body { |
| 28 | + body { |
29 | 29 | font-size: 2rem;
|
30 | 30 | display:flex;
|
31 | 31 | flex:1;
|
32 | 32 | min-height: 100vh;
|
33 | 33 | align-items: center;
|
34 |
| - } |
| 34 | + } |
35 | 35 |
|
36 |
| - .clock { |
| 36 | + .clock { |
37 | 37 | width: 30rem;
|
38 | 38 | height: 30rem;
|
39 | 39 | border:20px solid white;
|
|
42 | 42 | position: relative;
|
43 | 43 | padding:2rem;
|
44 | 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 |
| - } |
| 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 | 50 |
|
51 |
| - .clock-face { |
| 51 | + .clock-face { |
52 | 52 | position: relative;
|
53 | 53 | width: 100%;
|
54 | 54 | height: 100%;
|
55 | 55 | transform: translateY(-3px); /* account for the height of the clock hands */
|
56 |
| - } |
| 56 | + } |
57 | 57 |
|
58 |
| - .hand { |
| 58 | + .hand { |
59 | 59 | width:50%;
|
60 | 60 | height:6px;
|
61 | 61 | background:black;
|
62 | 62 | position: absolute;
|
63 | 63 | top:50%;
|
64 |
| - } |
| 64 | + border-radius: 10px 0 0 10px; |
65 | 65 |
|
66 |
| - </style> |
| 66 | + transform: rotate(90deg); |
| 67 | + transform-origin: right; |
| 68 | + transition: all 0.5s; |
| 69 | + transition-timing-function: cubic-bezier(0.01, 1.14, 1, 1.08); |
| 70 | + } |
67 | 71 |
|
68 |
| - <script> |
| 72 | + .hour-hand { |
| 73 | + width: 30%; |
| 74 | + left: 20%; |
| 75 | + } |
69 | 76 |
|
| 77 | + </style> |
70 | 78 |
|
71 |
| - </script> |
| 79 | + <script type="text/javascript"> |
| 80 | + |
| 81 | + const secondHand = document.querySelector('.second-hand'); |
| 82 | + const minHand = document.querySelector('.min-hand'); |
| 83 | + const hourHand = document.querySelector('.hour-hand'); |
| 84 | + function setDate() { |
| 85 | + const time = new Date(); |
| 86 | + const secondDegrees = time.getSeconds() /60 * 360 + 90; |
| 87 | + const minDegrees = time.getMinutes() / 60 * 360 + 90; |
| 88 | + const hourDegrees = time.getHours() / 12 * 360 + 90; |
| 89 | + |
| 90 | + secondHand.style.transform = `rotate(${secondDegrees}deg)`; |
| 91 | + minHand.style.transform = `rotate(${minDegrees}deg)`; |
| 92 | + hourHand.style.transform = `rotate(${hourDegrees}deg)`; |
| 93 | + |
| 94 | + } |
| 95 | + |
| 96 | + setInterval(setDate, 1000); |
| 97 | + |
| 98 | + </script> |
72 | 99 | </body>
|
73 | 100 | </html>
|
0 commit comments