|
9 | 9 |
|
10 | 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">hour</div> |
| 13 | + <div class="hand min-hand">min</div> |
| 14 | + <div class="hand second-hand">sec</div> |
15 | 15 | </div> |
16 | 16 | </div> |
17 | 17 |
|
|
54 | 54 | height: 100%; |
55 | 55 | transform: translateY(-3px); /* account for the height of the clock hands */ |
56 | 56 | } |
57 | | - |
58 | 57 | .hand { |
59 | 58 | width:50%; |
60 | 59 | height:6px; |
61 | | - background:black; |
62 | 60 | position: absolute; |
| 61 | + background: black; |
63 | 62 | top:50%; |
| 63 | + transform-origin: 100%; |
| 64 | + transform: rotate(90deg); |
| 65 | + transition: ; |
| 66 | + transition-timing-function: cubic-bezier(.1, 2.7, .58, 1); |
64 | 67 | } |
65 | | - |
66 | 68 | </style> |
67 | 69 |
|
68 | 70 | <script> |
| 71 | + const secondHand = document.querySelector('.second-hand') |
| 72 | + const minuteHand = document.querySelector('.min-hand') |
| 73 | + const hourHand = document.querySelector('.hour-hand'); |
| 74 | + const hand = document.querySelector('.hand'); |
| 75 | + |
| 76 | + function setDate() { |
| 77 | + const now = new Date(); |
69 | 78 |
|
| 79 | + const seconds = now.getSeconds(); |
| 80 | + const secondsDegrees = convert(seconds); |
| 81 | + secondHand.style.transform = `rotate(${secondsDegrees}deg)`; |
| 82 | + |
| 83 | + const minutes = now.getMinutes(); |
| 84 | + const minutesDegrees = convert(minutes); |
| 85 | + minuteHand.style.transform = `rotate(${minutesDegrees}deg)`; |
| 86 | + |
| 87 | + const hours = now.getHours(); |
| 88 | + const hoursDegrees = convert(hours); |
| 89 | + hourHand.style.transform = `rotate(${hoursDegrees}deg)`; |
| 90 | + if (seconds === 0 || minutes === 0 || hours === 0) { |
| 91 | + hand.style.transition = 'none'; |
| 92 | + } |
| 93 | + } |
70 | 94 |
|
| 95 | + function convert (numb) { |
| 96 | + return (((numb / 60) * 360) + 90); |
| 97 | + } |
| 98 | + setInterval(setDate, 1000); |
71 | 99 | </script> |
72 | 100 | </body> |
73 | 101 | </html> |
0 commit comments