Visitar URL original
Merge branch 'master' of https://github.com/kiouv/JavaScript30 · wesbos/JavaScript30@c54be62 · GitHub
Skip to content

Commit c54be62

Browse files
Cedric MagninCedric Magnin
authored andcommitted
Merge branch 'master' of https://github.com/kiouv/JavaScript30
2 parents 04834d2 + fd03aef commit c54be62

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
<div class="clock">
1111
<div class="clock-face">
12-
<div class="hand hour-hand"></div>
13-
<div class="hand min-hand"></div>
1412
<div class="hand second-hand"></div>
13+
<div class="hand min-hand"></div>
14+
<div class="hand hour-hand"></div>
1515
</div>
1616
</div>
1717

@@ -61,12 +61,47 @@
6161
background:black;
6262
position: absolute;
6363
top:50%;
64+
transform-origin: 100%;
65+
transform: rotate(90deg);
66+
transition: all 0.5s;
67+
transition-timing-function: cubic-bezier(0.26, 1.96, 0.65, 0.54);
68+
}
69+
.hour-hand {
70+
width: 40%;
71+
right: 50%;
72+
}
73+
.second-hand {
74+
background: white;
6475
}
6576

6677
</style>
6778

6879
<script>
6980

81+
const hourHand = document.querySelector('.hour-hand');
82+
const minuteHand = document.querySelector('.min-hand');
83+
const secondHand = document.querySelector('.second-hand');
84+
85+
function setDate() {
86+
const now = new Date();
87+
88+
const hour = now.getHours();
89+
console.log(hour);
90+
const hoursDegrees = ((hour / 60) * 360) + 90;
91+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
92+
93+
const min = now.getMinutes();
94+
console.log(min);
95+
const minutesDegrees = ((min / 60) * 360) + 90;
96+
minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;
97+
98+
const seconds = now.getSeconds();
99+
const secondsDegrees = ((seconds / 60) * 360) + 90;
100+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
101+
102+
}
103+
104+
setInterval(setDate, 1000);
70105

71106
</script>
72107
</body>

0 commit comments

Comments
 (0)