Visitar URL original
JDH: Finish #05: Flex Gallery · jdhines/JavaScript30@36e3b7c · GitHub
Skip to content

Commit 36e3b7c

Browse files
author
Jess Hines
committed
JDH: Finish wesbos#5: Flex Gallery
1 parent 8ee5183 commit 36e3b7c

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
.panels {
2525
min-height:100vh;
2626
overflow: hidden;
27+
display: flex;
2728
}
2829

2930
.panel {
31+
flex: 1;
3032
background:#6B0F9C;
3133
box-shadow:inset 0 0 0 5px rgba(255,255,255,0.1);
3234
color:white;
@@ -41,6 +43,10 @@
4143
font-size: 20px;
4244
background-size:cover;
4345
background-position:center;
46+
justify-content: center;
47+
align-items: center;
48+
display: flex;
49+
flex-direction: column;
4450
}
4551

4652

@@ -50,12 +56,29 @@
5056
.panel4 { background-image:url(https://source.unsplash.com/ITjiVXcwVng/1500x1500); }
5157
.panel5 { background-image:url(https://source.unsplash.com/3MNzGlQM7qs/1500x1500); }
5258

59+
/* Flex Children */
5360
.panel > * {
5461
margin:0;
5562
width: 100%;
5663
transition:transform 0.5s;
64+
flex: 1 0 auto;
65+
display: flex;
66+
justify-content: center;
67+
align-items: center;
68+
}
69+
.panel > *:first-child {
70+
transform: translateY(-100%);
71+
}
72+
.panel.open-active > *:first-child {
73+
transform: translateY(0);
74+
}
75+
76+
.panel > *:last-child {
77+
transform: translateY(100%);
78+
}
79+
.panel.open-active > *:last-child {
80+
transform: translateY(0);
5781
}
58-
5982
.panel p {
6083
text-transform: uppercase;
6184
font-family: 'Amatic SC', cursive;
@@ -68,6 +91,7 @@
6891

6992
.panel.open {
7093
font-size:40px;
94+
flex: 5;
7195
}
7296

7397
.cta {
@@ -107,7 +131,26 @@
107131
</div>
108132

109133
<script>
134+
const panels = document.querySelectorAll('.panel');
135+
136+
function toggleOpen() {
137+
if (this.classList.contains('open')) {
138+
//closing an open panel
139+
this.classList.remove('open');
140+
} else {
141+
//clicking another panel that isn't currently open
142+
panels.forEach(panel => panel.classList.remove('open'));
143+
this.classList.toggle('open');
144+
}
145+
}
110146

147+
function toggleActive(e) {
148+
if(e.propertyName.includes('flex')) {
149+
this.classList.toggle('open-active');
150+
}
151+
}
152+
panels.forEach(panel => panel.addEventListener('click',toggleOpen));
153+
panels.forEach(panel => panel.addEventListener('transitionend',toggleActive));
111154
</script>
112155

113156

0 commit comments

Comments
 (0)