Visitar URL original
Completed Flex Panel Gallery · wesbos/JavaScript30@7bf4025 · GitHub
Skip to content

Commit 7bf4025

Browse files
committed
Completed Flex Panel Gallery
1 parent b43559b commit 7bf4025

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,22 @@
1717
body {
1818
margin: 0;
1919
}
20+
2021
*, *:before, *:after {
2122
box-sizing: inherit;
2223
}
2324

2425
.panels {
26+
display: flex;
27+
flex-direction: row;
2528
min-height:100vh;
2629
overflow: hidden;
2730
}
2831

2932
.panel {
33+
display: flex;
34+
flex-direction: column;
35+
flex: 1;
3036
background:#6B0F9C;
3137
box-shadow:inset 0 0 0 5px rgba(255,255,255,0.1);
3238
color:white;
@@ -54,8 +60,17 @@
5460
margin:0;
5561
width: 100%;
5662
transition:transform 0.5s;
63+
display: flex;
64+
flex: 1 0 auto;
65+
justify-content: center;
66+
align-items: 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,6 +123,20 @@
107123
</div>
108124

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

111141
</script>
112142

0 commit comments

Comments
 (0)