Skip to content

Commit 74df438

Browse files
committed
code along with wesbos#2 css clock
1 parent 60b13d4 commit 74df438

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

02 - JS and CSS Clock/index-START.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,38 @@
6262
background:black;
6363
position: absolute;
6464
top:50%;
65+
66+
transform-origin: 100%;
67+
transform: rotate(90deg);
68+
transition: all 0.5s;
69+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
6570
}
6671

6772
</style>
6873

6974
<script>
75+
const secondHand = document.querySelector('.second-hand');
76+
const minHand = document.querySelector('.min-hand');
77+
const hourHand = document.querySelector('.hour-hand');
78+
79+
function setDate(){
80+
const now = new Date();
81+
82+
const seconds = now.getSeconds();
83+
const secondsDegrees = ((seconds/60) * 360) + 90;
84+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
85+
86+
const min = now.getMinutes();
87+
const minDegrees = ((min/60) * 360) + 90;
88+
minHand.style.transform = `rotate(${minDegrees}deg)`;
89+
90+
const hour = now.getHours();
91+
const hourDegrees = ((min/12) * 360) + 90;
92+
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
93+
}
7094

95+
//tells how often setDate should run in milliseconds
96+
setInterval(setDate, 1000);
7197

7298
</script>
7399
</body>

0 commit comments

Comments
 (0)