Skip to content

Commit 3841547

Browse files
committed
Lesson 3 complate.
1 parent be4c87f commit 3841547

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,48 @@
6060
height:6px;
6161
background:black;
6262
position: absolute;
63-
top:50%;
63+
top: 50%;
64+
transform-origin: 100%;
65+
transform:rotate(90deg);
66+
transition: all 0.05s;
67+
transition-timing-function: cubic-bezier(0.9, 0.43, 0, 0.96);
68+
}
69+
70+
.hour-hand {
71+
width: 25%;
72+
top: 50%;
73+
left: 25%;
74+
}
75+
76+
.min-hand {
77+
width: 40%;
78+
left: 10%;
6479
}
6580

6681
</style>
6782

6883
<script>
84+
var secondHand = document.querySelector('.second-hand');
85+
var minuteHand = document.querySelector('.min-hand');
86+
var hourHand = document.querySelector('.hour-hand');
87+
88+
function setDate() {
89+
var now = new Date();
90+
91+
var seconds = now.getSeconds();
92+
var minutes = now.getMinutes();
93+
var hours = now.getHours();
94+
95+
var secondsDegrees = ((seconds / 60) * 360) + 90;
96+
var minutesDegrees = ((minutes / 60) * 360) + 90;
97+
var hoursDegrees = ((hours / 60) * 360) + 90;
98+
99+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
100+
minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;
101+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
102+
};
69103

104+
setInterval(setDate, 1000);
70105

71106
</script>
72107
</body>

03 - CSS Variables/index-START.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2222

2323
<style>
2424

25+
:root {
26+
--base: #ffc600;
27+
--spacing: 10px;
28+
--blur: 10px;
29+
}
30+
31+
img {
32+
padding: var(--spacing);
33+
background: var(--base);
34+
filter: blur(var(--blur));
35+
}
36+
37+
.hl {
38+
color: var(--base);
39+
}
40+
2541
/*
2642
misc styles, nothing to do with CSS variables
2743
*/
@@ -48,6 +64,15 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4864
</style>
4965

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

5378
</body>

0 commit comments

Comments
 (0)