Skip to content

Commit f3b773c

Browse files
committed
1 parent df78b29 commit f3b773c

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

02 - JS + CSS Clock/index.html

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>JS + CSS Clock</title>
6+
<script src="http://localhost:35729/livereload.js"></script>
67
</head>
78
<body>
89

@@ -61,36 +62,37 @@
6162
background:black;
6263
position: absolute;
6364
top:50%;
64-
transform-origin: 100%;
65-
transform: rotate(90deg);
65+
transform-origin: right;
6666
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%;
6875
}
69-
</style>
7076

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>
7578

79+
<script>
80+
const elmSec = document.querySelector('.second-hand');
81+
const elmMin = document.querySelector('.min-hand');
82+
const elmHrs = document.querySelector('.hour-hand');
7683
function setDate() {
84+
const toDegree = val => val/60*360 + 90;
7785
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)`;
9093
}
91-
94+
setDate();
9295
setInterval(setDate, 1000);
93-
94-
</script>
96+
</script>
9597
</body>
9698
</html>

0 commit comments

Comments
 (0)