Visitar URL original
completed! added some styling to the hands to make them more realistic · wesbos/JavaScript30@7e84057 · GitHub
Skip to content

Commit 7e84057

Browse files
committed
completed! added some styling to the hands to make them more realistic
1 parent a308e98 commit 7e84057

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

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

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
5-
<title>Document</title>
5+
<title>JavaScript Clock</title>
66
</head>
77
<body>
88

@@ -57,16 +57,55 @@
5757

5858
.hand {
5959
width:50%;
60-
height:6px;
61-
background:black;
60+
height:3.4px;
6261
position: absolute;
6362
top:50%;
63+
transform-origin: 100%;
64+
transform: rotate(90deg);
65+
transition: all 0.05s;
66+
transition-timing-function:cubic-bezier(0.8, 0.2, 0.85, 2.35);
67+
}
68+
69+
.second-hand {
70+
background: red;
71+
}
72+
73+
.min-hand, .hour-hand {
74+
background: black;
75+
}
76+
77+
.hand.hour-hand {
78+
width: 45%;
79+
height: 5px;
80+
margin-left: 14.5px;
6481
}
6582

6683
</style>
6784

6885
<script>
6986

87+
const secondHand = document.querySelector('.second-hand')
88+
89+
const minsHand = document.querySelector('.min-hand')
90+
91+
const hourHand = document.querySelector('.hour-hand')
92+
93+
function setDate() {
94+
const now = new Date()
95+
const seconds = now.getSeconds()// uses Date to get current seconds
96+
const secondsDegrees = ((seconds / 60) * 360) + 90
97+
secondHand.style.transform =`rotate(${secondsDegrees}deg)`
98+
99+
const minutes = now.getMinutes()
100+
const minsDegrees = ((minutes / 60) * 360) + 90
101+
minsHand.style.transform = `rotate(${minsDegrees}deg)`
102+
103+
const hour = now.getHours()
104+
const hourDegrees = ((hour / 12) * 360) + 90
105+
hourHand.style.transform = `rotate(${hourDegrees}deg)`
106+
}
107+
108+
setInterval(setDate, 1000)
70109

71110
</script>
72111
</body>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
transition: all 0.05s;
6767
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
6868
}
69+
}
6970
</style>
7071

7172
<script>

0 commit comments

Comments
 (0)