Skip to content

Commit dbd8d45

Browse files
committed
Did day 2 and 3 :)
1 parent c8012a8 commit dbd8d45

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,36 @@
6161
background:black;
6262
position: absolute;
6363
top:50%;
64+
transform-origin: 100%;
65+
transform: rotate(90deg);
66+
transition: all 0.05s;
67+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
6468
}
6569

6670
</style>
6771

6872
<script>
73+
const secondHand = document.querySelector('.second-hand');
74+
const minuteHand = document.querySelector('.min-hand');
75+
const hourHand = document.querySelector('.hour-hand');
6976

77+
function setDate() {
78+
const now = new Date();
7079

80+
const seconds = now.getSeconds();
81+
const secondsDegrees = ((seconds / 60) * 360) + 90;
82+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
83+
84+
const minutes = now.getMinutes();
85+
const minutesDegrees = ((minutes / 60) * 360) + 90;
86+
minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;
87+
88+
const hours = now.getHours();
89+
const hoursDegrees = ((hours / 12) * 360) + 90;
90+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
91+
}
92+
93+
setInterval(setDate, 1000);
7194
</script>
7295
</body>
7396
</html>

03 - CSS Variables/index-START.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2121
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">
2222

2323
<style>
24+
:root {
25+
--base: #ffc600;
26+
--spacing: 10px;
27+
--blur: 10px;
28+
}
29+
30+
img {
31+
padding: var(--spacing);
32+
background: var(--base);
33+
filter: blur(var(--blur));
34+
}
35+
36+
.hl {
37+
color: var(--base);
38+
}
2439

2540
/*
2641
misc styles, nothing to do with CSS variables
@@ -48,6 +63,15 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4863
</style>
4964

5065
<script>
66+
const inputs = document.querySelectorAll('.controls input');
67+
68+
function handleUpdate() {
69+
const suffix = this.dataset.sizing || '';
70+
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix);
71+
}
72+
73+
inputs.forEach(input => input.addEventListener('change', handleUpdate));
74+
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));
5175
</script>
5276

5377
</body>

0 commit comments

Comments
 (0)