|
62 | 62 | background: black; |
63 | 63 | position: absolute; |
64 | 64 | top: 50%; |
| 65 | + transform-origin: 100%; |
| 66 | + transform: rotate(90deg); |
| 67 | + transition: all 0.5s; |
| 68 | + transition-timing-function: cubic-bezier(0.1, 2, 0.5, 1); |
| 69 | + } |
| 70 | + |
| 71 | + .second-hand { |
| 72 | + height: 3px; |
65 | 73 | } |
66 | 74 |
|
67 | 75 | </style> |
68 | 76 |
|
69 | 77 | <script> |
70 | 78 |
|
| 79 | + const secondHand = document.querySelector('.second-hand'); |
| 80 | + const minutesHand = document.querySelector('.min-hand'); |
| 81 | + const hoursHand = document.querySelector('.hour-hand'); |
| 82 | + |
| 83 | + const hands = document.querySelectorAll('.hand'); |
| 84 | + |
| 85 | + function setDate() { |
| 86 | + const now = new Date(); |
| 87 | + const seconds = now.getSeconds(); |
| 88 | + const minutes = now.getMinutes(); |
| 89 | + const hours = now.getHours(); |
| 90 | + console.log(`${hours}:${minutes}:${seconds}`); |
| 91 | + |
| 92 | + const secondsDegrees = (seconds / 60 * 360) + 90; |
| 93 | + const minutesDegrees = (minutes / 60 * 365) + 90; |
| 94 | + const hoursDegrees = (hours / 12 * 365) + 90; |
| 95 | + |
| 96 | + // Pause transition animation when second hand goes from 59 seconds to 0 |
| 97 | + if (secondHand.style.transform == 'rotate(444deg)'){ |
| 98 | + secondHand.style.transition = 'none'; |
| 99 | + } else if (secondHand.style.transform == 'rotate(90deg)') { |
| 100 | + secondHand.style.transition = 'all 0.5s'; |
| 101 | + } |
| 102 | + |
| 103 | + secondHand.style.transform = `rotate(${secondsDegrees}deg)`; |
| 104 | + minutesHand.style.transform = `rotate(${minutesDegrees}deg)`; |
| 105 | + hoursHand.style.transform = `rotate(${hoursDegrees}deg)`; |
| 106 | + |
| 107 | + } |
71 | 108 |
|
| 109 | + setInterval(setDate, 1000); |
72 | 110 | </script> |
73 | 111 | </body> |
74 | 112 | </html> |
0 commit comments