|
3 | 3 | <head>
|
4 | 4 | <meta charset="UTF-8">
|
5 | 5 | <title>JS + CSS Clock</title>
|
| 6 | + <script src="http://localhost:35729/livereload.js"></script> |
6 | 7 | </head>
|
7 | 8 | <body>
|
8 | 9 |
|
|
61 | 62 | background:black;
|
62 | 63 | position: absolute;
|
63 | 64 | top:50%;
|
64 |
| - transform-origin: 100%; |
65 |
| - transform: rotate(90deg); |
| 65 | + transform-origin: right; |
66 | 66 | transition: all 0.05s;
|
67 |
| - transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1); |
| 67 | + transition-timing-function: cubic-bezier(0.41, 2.72, 0.83, 0.74); |
| 68 | + } |
| 69 | + .second-hand { |
| 70 | + height: 2px; |
| 71 | + } |
| 72 | + .hour-hand { |
| 73 | + width: 30%; |
| 74 | + right: 50%; |
68 | 75 | }
|
69 |
| -</style> |
70 | 76 |
|
71 |
| -<script> |
72 |
| - const secondHand = document.querySelector('.second-hand'); |
73 |
| - const minsHand = document.querySelector('.min-hand'); |
74 |
| - const hourHand = document.querySelector('.hour-hand'); |
| 77 | + </style> |
75 | 78 |
|
| 79 | + <script> |
| 80 | + const elmSec = document.querySelector('.second-hand'); |
| 81 | + const elmMin = document.querySelector('.min-hand'); |
| 82 | + const elmHrs = document.querySelector('.hour-hand'); |
76 | 83 | function setDate() {
|
| 84 | + const toDegree = val => val/60*360 + 90; |
77 | 85 | const now = new Date();
|
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)`; |
86 |
| - |
87 |
| - const hour = now.getMinutes(); |
88 |
| - const hourDegrees = ((mins / 12) * 360) + 90; |
89 |
| - hourHand.style.transform = `rotate(${hourDegrees}deg)`; |
| 86 | + const sec = now.getSeconds(); |
| 87 | + const min = now.getMinutes(); |
| 88 | + const hrs = now.getHours(); |
| 89 | + console.log(now) |
| 90 | + elmSec.style.transform = `rotate(${toDegree(sec)}deg)`; |
| 91 | + elmMin.style.transform = `rotate(${toDegree(min)}deg)`; |
| 92 | + elmHrs.style.transform = `rotate(${hrs/24*360 + 90}deg)`; |
90 | 93 | }
|
91 |
| - |
| 94 | + setDate(); |
92 | 95 | setInterval(setDate, 1000);
|
93 |
| - |
94 |
| -</script> |
| 96 | + </script> |
95 | 97 | </body>
|
96 | 98 | </html>
|
0 commit comments