Visitar URL original
02: add my JavaScript code · wesbos/JavaScript30@387b986 · GitHub
Skip to content

Commit 387b986

Browse files
committed
02: add my JavaScript code
Signed-off-by: Soshi Katsuta <soshi.katsuta@gmail.com>
1 parent d094723 commit 387b986

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

‎02 - JS + CSS Clock/index-START.html‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@
6161
background:black;
6262
position: absolute;
6363
top:50%;
64+
transform-origin: 100%;
65+
transform: rotate(90deg);
66+
transition: all 0.05s;
67+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
6468
}
6569

6670
</style>
6771

68-
<script>
72+
<script src="index.js"></script>
6973

70-
71-
</script>
7274
</body>
7375
</html>

‎02 - JS + CSS Clock/index.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const units = [
2+
{
3+
elem: document.querySelector('.second-hand'),
4+
method: 'getSeconds',
5+
max: 60
6+
},
7+
{
8+
elem: document.querySelector('.min-hand'),
9+
method: 'getMinutes',
10+
max: 60
11+
},
12+
{
13+
elem: document.querySelector('.hour-hand'),
14+
method: 'getHours',
15+
max: 12
16+
}
17+
];
18+
19+
setInterval(setDate, 1000);
20+
21+
function setDate() {
22+
units.forEach(unit => {
23+
const now = new Date();
24+
const deg = (now[unit.method]() / unit.max) * 360 + 90;
25+
unit.elem.style.transform = `rotate(${deg}deg)`;
26+
});
27+
}

0 commit comments

Comments
 (0)