Skip to content

Commit aaf3d3c

Browse files
authored
Merge pull request #3 from benschac/05
05
2 parents 4cafde2 + 8865d09 commit aaf3d3c

4 files changed

Lines changed: 130 additions & 23 deletions

File tree

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
1515
<input type="range" name="blur" min="0" max="25" value="10" data-sizing="px">
1616

1717
<label for="base">Base Color</label>
18-
<input type="color" name="base" value="#ffc600">
18+
<input type="color" name="base" value="#ffcf00">
1919
</div>
2020

2121
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">
@@ -26,6 +26,25 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2626
misc styles, nothing to do with CSS variables
2727
*/
2828

29+
:root {
30+
--base: #ffc600;
31+
--spacing: 10px;
32+
33+
}
34+
35+
h1 {
36+
color: var(--base);
37+
--blur: 0px;
38+
39+
}
40+
41+
img {
42+
padding: var(--spacing);
43+
background: var(--base);
44+
filter: blur(var(--blur));
45+
46+
}
47+
2948
body {
3049
text-align: center;
3150
}
@@ -53,6 +72,15 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
5372
</style>
5473

5574
<script>
75+
const inputs = document.querySelectorAll('.controls input');
76+
function handleUpdate() {
77+
const suffux = this.dataset.sizing || '';
78+
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffux);
79+
}
80+
81+
inputs.forEach(input => input.addEventListener('change', handleUpdate));
82+
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));
83+
5684
</script>
5785

5886
</body>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
.panels {
2525
min-height:100vh;
2626
overflow: hidden;
27+
display: flex;
2728
}
2829

2930
.panel {
@@ -41,6 +42,12 @@
4142
font-size: 20px;
4243
background-size:cover;
4344
background-position:center;
45+
46+
flex: 1 0 auto;
47+
/*justify-content: center;*/
48+
align-content: center;
49+
display: flex;
50+
flex-direction: column;
4451
}
4552

4653

@@ -54,6 +61,26 @@
5461
margin:0;
5562
width: 100%;
5663
transition:transform 0.5s;
64+
flex: 1 0 auto;
65+
justify-content: center;
66+
align-items: center;
67+
}
68+
69+
70+
.panel > *:first-child {
71+
transform: translateY(-100%);
72+
}
73+
74+
.panel > *:last-child {
75+
transform: translateY(100%);
76+
}
77+
78+
.panel.open-active > *:first-child {
79+
transform: translateY(0);
80+
}
81+
82+
.panel.open-active > *:last-child {
83+
transform: translateY(0);
5784
}
5885

5986
.panel p {
@@ -68,6 +95,7 @@
6895

6996
.panel.open {
7097
font-size:40px;
98+
flex: 5;
7199
}
72100

73101
.cta {
@@ -107,7 +135,25 @@
107135
</div>
108136

109137
<script>
138+
const panels = document.querySelectorAll('.panel');
139+
140+
141+
function toggleOpen() {
142+
this.classList.toggle('open');
143+
}
144+
145+
function toggleActive(e) {
146+
if(e.propertyName.includes('flex')) {
147+
this.classList.toggle('open-active');
148+
console.log('hello');
149+
}
150+
151+
}
152+
153+
110154

155+
panels.forEach(panel => panel.addEventListener('click', toggleOpen));
156+
panels.forEach(panel => panel.addEventListener('transitionend', toggleActive));
111157
</script>
112158

113159

06 - Type Ahead/index-START.html

Lines changed: 0 additions & 22 deletions
This file was deleted.

06 - Type Ahead/index.html

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Type Ahead 👀</title>
6+
<link rel="stylesheet" href="style.css">
7+
</head>
8+
<body>
9+
10+
<form class="search-form">
11+
<input type="text" class="search" placeholder="City or State">
12+
<ul class="suggestions">
13+
<li>Filter for a city</li>
14+
<li>or a state</li>
15+
</ul>
16+
</form>
17+
<script>
18+
const endpoint = 'https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json';
19+
let cities = [];
20+
21+
fetch(endpoint)
22+
.then(blob => blob.json())
23+
.then(data => cities.push(...data));
24+
25+
function findMatches(wordToMatch, citiesArry) {
26+
return cities.filter(place => {
27+
const regex = new RegExp(wordToMatch, 'gi');
28+
return place.city.match(regex) || place.state.match(regex);
29+
});
30+
}
31+
32+
function displayMatches() {
33+
const matchArray = findMatches(this.value, cities);
34+
const html = matchArray.map(place => {
35+
const regex = new RegExp(this.value, 'gi');
36+
const cityName = place.city.replace(regex, `<span class="hl"> ${this.value}</span>`);
37+
const stateName = place.state.replace(regex, `<span class="hl">${this.value}</span>`);
38+
return `
39+
<li>
40+
<span class="name">${cityName}, ${stateName}</span>
41+
<span class="population">${place.population}</span>
42+
</li>
43+
`
44+
}).join('');
45+
46+
suggestions.innerHTML = html;
47+
}
48+
49+
const searchInput = document.querySelector('.search');
50+
const suggestions = document.querySelector('.suggestions');
51+
52+
searchInput.addEventListener('keyup', displayMatches);
53+
</script>
54+
</body>
55+
</html>

0 commit comments

Comments
 (0)