Skip to content

Commit 91203f2

Browse files
committed
JSS clock with glitch done
1 parent 7417d25 commit 91203f2

3 files changed

Lines changed: 51 additions & 4 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const secondHand = document.querySelector('.second-hand');
2+
const hourHand = document.querySelector('.hour-hand');
3+
const minsHand = document.querySelector('.min-hand');
4+
const glitch = document.querySelector('.fast');
5+
function setDate(){
6+
const date = new Date();
7+
const hour = date.getHours();
8+
const mins = date.getMinutes();
9+
const secs = date.getSeconds();
10+
const secsDeg = ((secs/60)*360)+90; //90 added for the offset we did initially
11+
const minsDeg = ((mins/60)*360)+90;
12+
const hoursDeg = ((hour/12)*360)+90;
13+
14+
if(secs === 0)
15+
secondHand.classList.add('fast');
16+
if(secs === 1)
17+
secondHand.classList.remove('fast');
18+
secondHand.style.transform = `rotate(${secsDeg}deg)`;
19+
minsHand.style.transform = `rotate(${minsDeg}deg)`;
20+
hourHand.style.transform = `rotate(${hoursDeg}deg)`;
21+
22+
console.log(`hour is ${hour}, mins is ${mins} and secs is ${secs}`);
23+
}
24+
25+
let myDate = setInterval(setDate,1000);
26+

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<div class="clock-face">
1212
<div class="hand hour-hand"></div>
1313
<div class="hand min-hand"></div>
14-
<div class="hand second-hand"></div>
14+
<div class="hand second-hand fast"></div>
1515
</div>
1616
</div>
1717

@@ -62,13 +62,30 @@
6262
background: black;
6363
position: absolute;
6464
top: 50%;
65+
transform-origin: 100%;
66+
transform: rotate(90deg);
67+
transition: all 0.05s;
68+
transition-timing-function: cubic-bezier(0.1,2.7,0.58,1);
6569
}
6670

67-
</style>
71+
.hour-hand{
72+
background-color:red;
73+
}
74+
75+
.min-hand{
76+
background-color:blue;
77+
}
6878

69-
<script>
79+
.second-hand{
80+
background-color:green;
81+
}
82+
83+
.fast{
84+
transition: all 0s;
85+
}
7086

87+
</style>
7188

72-
</script>
89+
<script src="JS_CSS_Clock.js"> </script>
7390
</body>
7491
</html>

02 - JS and CSS Clock/learning.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Things learnt while solving this project
2+
1: transform-origin
3+
2: background cover
4+
3: transition

0 commit comments

Comments
 (0)