Visitar URL original
Merge pull request #5 from cydseelen/flex · wesbos/JavaScript30@74a0879 · GitHub
Skip to content

Commit 74a0879

Browse files
authored
Merge pull request #5 from cydseelen/flex
Completed flex panel challenge.
2 parents d5f9347 + 85d8543 commit 74a0879

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@
1414
font-size: 20px;
1515
font-weight: 200;
1616
}
17-
17+
1818
body {
1919
margin: 0;
2020
}
21-
21+
2222
*, *:before, *:after {
2323
box-sizing: inherit;
2424
}
2525

2626
.panels {
2727
min-height: 100vh;
2828
overflow: hidden;
29+
display: flex;
2930
}
3031

3132
.panel {
@@ -43,6 +44,11 @@
4344
font-size: 20px;
4445
background-size: cover;
4546
background-position: center;
47+
flex: 1;
48+
justify-content: center;
49+
align-items: center;
50+
display: flex;
51+
flex-direction: column;
4652
}
4753

4854
.panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); }
@@ -56,20 +62,31 @@
5662
margin: 0;
5763
width: 100%;
5864
transition: transform 0.5s;
65+
/*border: 1px solid red;*/
66+
flex: 1 0 auto;
67+
display: flex;
68+
justify-content: center;
69+
align-items: center;
5970
}
6071

72+
.panel > *:first-child { transform: translateY(-100%); }
73+
.panel.open-active > *:first-child { transform: translateY(0); }
74+
.panel > *:last-child { transform: translateY(100%); }
75+
.panel.open-active > *:last-child { transform: translateY(0); }
76+
6177
.panel p {
6278
text-transform: uppercase;
6379
font-family: 'Amatic SC', cursive;
6480
text-shadow: 0 0 4px rgba(0, 0, 0, 0.72), 0 0 14px rgba(0, 0, 0, 0.45);
6581
font-size: 2em;
6682
}
67-
83+
6884
.panel p:nth-child(2) {
6985
font-size: 4em;
7086
}
7187

7288
.panel.open {
89+
flex: 5;
7390
font-size: 40px;
7491
}
7592

@@ -105,6 +122,21 @@
105122
</div>
106123

107124
<script>
125+
const panels = document.querySelectorAll('.panel');
126+
127+
function toggleOpen() {
128+
this.classList.toggle('open');
129+
}
130+
131+
function toggleActive(e) {
132+
console.log(event.propertyName);
133+
if(event.propertyName.includes('flex')){
134+
this.classList.toggle('open-active');
135+
}
136+
}
137+
138+
panels.forEach(panel => panel.addEventListener('click', toggleOpen));
139+
panels.forEach(panel => panel.addEventListener('transitionend', toggleActive));
108140

109141
</script>
110142

0 commit comments

Comments
 (0)