|
69 | 69 | </style>
|
70 | 70 |
|
71 | 71 | <script>
|
72 |
| - const secondHand = document.querySelector('.second-hand'); |
73 |
| - const minsHand = document.querySelector('.min-hand'); |
74 |
| - const hourHand = document.querySelector('.hour-hand'); |
| 72 | + const secondHand = document.querySelector('.second-hand') |
| 73 | + const minuteHand = document.querySelector('.min-hand') |
| 74 | + const hourHand = document.querySelector('.hour-hand') |
75 | 75 |
|
76 |
| - function setDate() { |
77 |
| - const now = new Date(); |
| 76 | + minuteHand.style.height = `4px` |
| 77 | + secondHand.style.height = `2px` |
78 | 78 |
|
79 |
| - const seconds = now.getSeconds(); |
80 |
| - const secondsDegrees = ((seconds / 60) * 360) + 90; |
81 |
| - secondHand.style.transform = `rotate(${secondsDegrees}deg)`; |
82 |
| - |
83 |
| - const mins = now.getMinutes(); |
84 |
| - const minsDegrees = ((mins / 60) * 360) + 90; |
85 |
| - minsHand.style.transform = `rotate(${minsDegrees}deg)`; |
| 79 | + function getDegrees(n) { |
| 80 | + return (( n / 60 ) * 360) + 90 |
| 81 | + } |
86 | 82 |
|
87 |
| - const hour = now.getMinutes(); |
88 |
| - const hourDegrees = ((mins / 12) * 360) + 90; |
89 |
| - hourHand.style.transform = `rotate(${hourDegrees}deg)`; |
| 83 | +function setDate() { |
| 84 | + const now = new Date() |
| 85 | + const seconds = now.getSeconds() |
| 86 | + const minutes = now.getMinutes() |
| 87 | + function getHour(){ |
| 88 | + var rawHour = now.getHours() |
| 89 | + if ( rawHour > 12 ) { |
| 90 | + return (rawHour - 12) * 5 |
| 91 | + } else { |
| 92 | + return rawHour * 5 |
| 93 | + } |
90 | 94 | }
|
| 95 | + const hours = getHour() |
| 96 | + |
| 97 | + const secondsDegrees = getDegrees(seconds) |
| 98 | + const minutesDegrees = getDegrees(minutes) |
| 99 | + const hoursDegrees = getDegrees(hours) + ((( minutesDegrees - 90 ) / 360 ) * 30 ) |
| 100 | + secondHand.style.transform = `rotate(${secondsDegrees}deg)` |
| 101 | + minuteHand.style.transform = `rotate(${minutesDegrees}deg)` |
| 102 | + hourHand.style.transform = `rotate(${hoursDegrees}deg)` |
| 103 | + |
| 104 | + console.log(secondsDegrees + " " + minutesDegrees + " " + hoursDegrees) |
| 105 | + console.log(((secondsDegrees - 90) / 360) * 30) |
| 106 | +} |
91 | 107 |
|
92 |
| - setInterval(setDate, 1000); |
| 108 | +setInterval(setDate, 1000) |
93 | 109 |
|
94 | 110 | </script>
|
95 | 111 | </body>
|
|
0 commit comments