Skip to content

Commit 396bbd3

Browse files
committed
finish flex panel gallery
1 parent 60cab87 commit 396bbd3

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

05 - Flex Panel Gallery/index-START.html

Lines changed: 29 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,11 @@
4142
font-size: 20px;
4243
background-size:cover;
4344
background-position:center;
45+
flex: 1;
46+
display: flex;
47+
align-items: center;
48+
justify-content: center;
49+
flex-direction: column;
4450
}
4551

4652

@@ -54,8 +60,17 @@
5460
margin:0;
5561
width: 100%;
5662
transition:transform 0.5s;
63+
flex: 1 0 auto;
64+
display: flex;
65+
align-items: center;
66+
justify-content: center;
5767
}
5868

69+
.panel > *:first-child { transform: translateY(-100%);}
70+
.panel.open-active > *:first-child { transform: translateY(0%);}
71+
.panel > *:last-child { transform: translateY(100%);}
72+
.panel.open-active > *:last-child { transform: translateY(0);}
73+
5974
.panel p {
6075
text-transform: uppercase;
6176
font-family: 'Amatic SC', cursive;
@@ -67,6 +82,7 @@
6782
}
6883

6984
.panel.open {
85+
flex: 5;
7086
font-size:40px;
7187
}
7288

@@ -107,7 +123,20 @@
107123
</div>
108124

109125
<script>
126+
const panels = document.querySelectorAll('.panel');
127+
128+
function toggleActive(e) {
129+
if (e.propertyName.includes('flex')) {
130+
this.classList.toggle('open-active');
131+
}
132+
}
133+
134+
function toggleOpen() {
135+
this.classList.toggle('open');
136+
}
110137

138+
panels.forEach(panel => panel.addEventListener('click', toggleOpen));
139+
panels.forEach(panel => panel.addEventListener('transitionend', toggleActive));
111140
</script>
112141

113142

0 commit comments

Comments
 (0)