Visitar URL original
Finished Flex Panels. The most interesting part is the reminder of al… · wesbos/JavaScript30@e27c13a · GitHub
Skip to content

Commit e27c13a

Browse files
author
Jonathan Alorda
committed
Finished Flex Panels. The most interesting part is the reminder of all the Event types and properties that DOM elements have, and how they can be leveraged. Also, skipped ahead to JS Ref vs Copying.
1 parent 4f269d9 commit e27c13a

2 files changed

Lines changed: 60 additions & 10 deletions

File tree

‎05 - Flex Panel Gallery/index-START.html‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
flex 0.7s cubic-bezier(0.61,-0.19, 0.7,-0.11),
4141
background 0.2s;
4242
font-size: 20px;
43-
background-size:cover;
44-
background-position:center;
43+
background-size: cover;
44+
background-position: center;
4545
flex: 1;
4646
justify-content: center;
4747
align-items: center;
@@ -56,20 +56,22 @@
5656
.panel4 { background-image:url(https://source.unsplash.com/ITjiVXcwVng/1500x1500); }
5757
.panel5 { background-image:url(https://source.unsplash.com/3MNzGlQM7qs/1500x1500); }
5858

59-
/* Flex Items*/
59+
/* Flex Items */
6060
.panel > * {
6161
margin:0;
6262
width: 100%;
6363
transition:transform 0.5s;
64-
border: 1px solid red;
64+
/* border: 1px solid red; */
6565
flex: 1 0 auto;
6666
display: flex;
6767
justify-content: center;
6868
align-items: center;
6969
}
7070

7171
.panel > *:first-child { transform: translateY(-100%); }
72+
.panel.open-active > *:first-child { transform: translateY(0) }
7273
.panel > *:last-child { transform: translateY(100%); }
74+
.panel.open-active > *:last-child { transform: translateY(0) }
7375

7476
.panel p {
7577
text-transform: uppercase;
@@ -82,7 +84,8 @@
8284
}
8385

8486
.panel.open {
85-
font-size:40px;
87+
font-size: 40px;
88+
flex: 5;
8689
}
8790

8891
.cta {
@@ -122,7 +125,21 @@
122125
</div>
123126

124127
<script>
128+
const panels = document.querySelectorAll('.panel')
125129

130+
function toggleOpen() {
131+
this.classList.toggle('open')
132+
}
133+
134+
function toggleActive(e) {
135+
console.log(e.propertyName)
136+
if (e.propertyName.includes('flex')) {
137+
this.classList.toggle('open-active')
138+
}
139+
}
140+
141+
panels.forEach(panel => panel.addEventListener('click', toggleOpen))
142+
panels.forEach(panel => panel.addEventListener('transitionend', toggleActive))
126143
</script>
127144

128145

‎14 - JavaScript References VS Copying/index-START.html‎

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,28 @@
77
<body>
88

99
<script>
10-
// start with strings, numbers and booleans
10+
// start with strings, numbers and booleans
11+
let age = 100
12+
let age2 = age
13+
console.log(age, age2)
14+
age = 200
15+
console.log(age, age2)
16+
17+
let name = "Jona"
18+
let name2 = name
19+
console.log(name, name2)
20+
name = "Joni"
21+
console.log(name, name2)
22+
1123

1224
// Let's say we have an array
1325
const players = ['Wes', 'Sarah', 'Ryan', 'Poppy'];
14-
1526
// and we want to make a copy of it.
27+
const team = players;
28+
console.log(players, team)
1629

1730
// You might think we can just do something like this:
18-
31+
// team[3] = 'Lux'
1932
// however what happens when we update that array?
2033

2134
// now here is the problem!
@@ -25,22 +38,42 @@
2538
// Why? It's because that is an array reference, not an array copy. They both point to the same array!
2639

2740
// So, how do we fix this? We take a copy instead!
28-
41+
const team2 = players.slice()
42+
team2[3] = 'Bert'
43+
console.log(`team2: ${team2}`)
2944
// one day
3045

3146
// or create a new array and concat the old one in
3247

3348
// or use the new ES6 Spread
49+
const team4 = [...players]
50+
team4[2] = 'Shaun'
51+
console.log(`team4: ${team4}`)
52+
53+
const team5 = Array.from(players)
54+
team5[0] = null
55+
console.log(`team5: ${team5}`)
56+
57+
const team6 = players.map(player => player)
3458

3559
// now when we update it, the original one isn't changed
3660

3761
// The same thing goes for objects, let's say we have a person object
3862

3963
// with Objects
4064

41-
// and think we make a copy:
65+
const person = {
66+
name: 'Jonathan',
67+
age: 243
68+
}
4269

70+
// and think we make a copy:
71+
const badCopyPerson = person
4372
// how do we take a copy instead?
73+
const wellCopiedPerson = Object.assign({}, person, {age: 34, number: 26})
74+
console.log(wellCopiedPerson)
75+
76+
const simpleCopy = Object.assign({}, person)
4477

4578
// We will hopefully soon see the object ...spread
4679

0 commit comments

Comments
 (0)