Skip to content

Commit 1d94d27

Browse files
author
Reed Hazen
committed
work on CSS variables
1 parent 5c8c6f6 commit 1d94d27

File tree

2 files changed

+95
-1
lines changed

2 files changed

+95
-1
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,23 @@
6868
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
6969
}
7070

71+
.hour-hand {
72+
width: 30%;
73+
left: 20%;
74+
}
75+
76+
.second-hand {
77+
background: red;
78+
height: 3px;
79+
}
80+
7181
</style>
7282

7383
<script>
7484
const secondHand = document.querySelector('.second-hand');
7585
const minuteHand = document.querySelector('.min-hand');
7686
const hourHand = document.querySelector('.hour-hand');
87+
const hand = document.querySelector('.hand');
7788
function setDate() {
7889
const now = new Date();
7990
const seconds = now.getSeconds();
@@ -85,7 +96,15 @@
8596
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
8697
minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;
8798
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
88-
// console.log('seconds', seconds);
99+
if (seconds === 59) {
100+
console.log('true');
101+
hand.style.removeProperty('transition');
102+
}
103+
if (seconds !== 59) {
104+
hand.style.transition = 'all 0.05s;';
105+
// secondHand.style.removeProperty('transition');
106+
}
107+
console.log('seconds', seconds);
89108
// console.log('minutes', minutes);
90109
// console.log('hours', hours);
91110
}

03 - CSS Variables/index-work.html

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Scoped CSS Variables and JS</title>
6+
</head>
7+
<body>
8+
<h2>Update CSS Variables with <span class='hl'>JS</span></h2>
9+
10+
<div class="controls">
11+
<label for="spacing">Spacing:</label>
12+
<input id="spacing" type="range" name="spacing" min="10" max="200" value="10" data-sizing="px">
13+
14+
<label for="blur">Blur:</label>
15+
<input id="blur" type="range" name="blur" min="0" max="25" value="10" data-sizing="px">
16+
17+
<label for="base">Base Color</label>
18+
<input id="base" type="color" name="base" value="#ffc600">
19+
</div>
20+
21+
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">
22+
23+
<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+
}
39+
40+
/*
41+
misc styles, nothing to do with CSS variables
42+
*/
43+
44+
body {
45+
text-align: center;
46+
background: #193549;
47+
color: white;
48+
font-family: 'helvetica neue', sans-serif;
49+
font-weight: 100;
50+
font-size: 50px;
51+
}
52+
53+
.controls {
54+
margin-bottom: 50px;
55+
}
56+
57+
input {
58+
width: 100px;
59+
}
60+
</style>
61+
62+
<script>
63+
const inputs = document.querySelectorAll('.controls input'); // this creates a NodeList, not an array. A NodeList does not have the same methods as arrays (much fewer), one that it does have is forEach
64+
65+
function handleUpdate() {
66+
const suffix = this.dataset.sizing || '';
67+
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix)
68+
}
69+
70+
inputs.forEach(input => input.addEventListener('change', handleUpdate));
71+
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));
72+
</script>
73+
74+
</body>
75+
</html>

0 commit comments

Comments
 (0)