|
62 | 62 | background:black;
|
63 | 63 | position: absolute;
|
64 | 64 | top:50%;
|
| 65 | + transform-origin: 100%; |
| 66 | + transform: rotate(90deg); |
| 67 | + transition: all 0.05s; |
| 68 | + transition-timing-function: cubic-bezier(0.1, 2.8, 0.82, 1); |
65 | 69 | }
|
66 | 70 |
|
67 | 71 | </style>
|
68 | 72 |
|
69 | 73 | <script>
|
70 | 74 |
|
| 75 | + // const secondHand = document.querySelector('.second-hand'); |
| 76 | + // const minHand = document.querySelector('.min-hand'); |
| 77 | + // const hourHand = document.querySelector('.hour-hand'); |
| 78 | + // |
| 79 | + // let secondHandAngle = 90; |
| 80 | + // let minHandAngle = 90; |
| 81 | + // let hourHandAngle = 90; |
| 82 | + // |
| 83 | + // function handChanger(unit) { |
| 84 | + // if (unit === 's') { |
| 85 | + // secondHand.style.transform = 'rotate('+secondHandAngle+'deg)'; |
| 86 | + // secondHandAngle += 6; |
| 87 | + // } else if (unit === 'm') { |
| 88 | + // minHand.style.transform = 'rotate('+minHandAngle+'deg)'; |
| 89 | + // minHandAngle += 6; |
| 90 | + // } else if (unit === 'h') { |
| 91 | + // hourHand.style.transform = 'rotate('+hourHandAngle+'deg)'; |
| 92 | + // hourHandAngle += 6; |
| 93 | + // } |
| 94 | + // } |
| 95 | + // |
| 96 | + // setInterval(function() { handChanger('s') }, 1000); |
| 97 | + // setInterval(function() { handChanger('m') }, 60000); |
| 98 | + // setInterval(function() { handChanger('h') }, 3600000); |
| 99 | + |
| 100 | + const secondHand = document.querySelector('.second-hand'); |
| 101 | + const minuteHand = document.querySelector('.min-hand'); |
| 102 | + const hourHand = document.querySelector('.hour-hand'); |
| 103 | + |
| 104 | + function setDate() { |
| 105 | + const now = new Date(); |
| 106 | + const seconds = now.getSeconds(); |
| 107 | + const secondsDegree = (seconds / 60) * 360 + 90; |
| 108 | + secondHand.style.transform = `rotate(${secondsDegree}deg)`; |
| 109 | + console.log(seconds); |
| 110 | + |
| 111 | + const minutes = now.getMinutes(); |
| 112 | + const minutesDegree = (minutes / 60) * 360 + 90; |
| 113 | + minuteHand.style.transform = `rotate(${minutesDegree}deg)`; |
| 114 | + console.log(minutes); |
| 115 | + |
| 116 | + const hours = now.getHours(); |
| 117 | + const hoursDegree = (hours / 12) * 360 + 90; |
| 118 | + hourHand.style.transform = `rotate(${hoursDegree}deg)`; |
| 119 | + console.log(hours); |
| 120 | + } |
| 121 | + |
| 122 | + setInterval(setDate,1000); |
71 | 123 |
|
72 | 124 | </script>
|
73 | 125 | </body>
|
|
0 commit comments