Skip to content

Commit 3a52dfa

Browse files
author
Alexander Besse
committed
wesbos#5 Completed.
1 parent 27df563 commit 3a52dfa

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

05 - Flex Panel Gallery/index-START.html

+41
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
.panels {
2727
min-height: 100vh;
2828
overflow: hidden;
29+
display: flex;
2930
}
3031

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

4855
.panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); }
@@ -56,6 +63,26 @@
5663
margin: 0;
5764
width: 100%;
5865
transition: transform 0.5s;
66+
flex: 1 0 auto;
67+
display: flex;
68+
justify-content: center;
69+
align-items: center;
70+
}
71+
72+
.panel > *:first-child {
73+
transform: translateY(-100%);
74+
}
75+
76+
.panel.open-active > *:first-child {
77+
transform: translateY(0);
78+
}
79+
80+
.panel > *:last-child {
81+
transform: translateY(100%);
82+
}
83+
84+
.panel.open-active > *:last-child {
85+
transform: translateY(0);
5986
}
6087

6188
.panel p {
@@ -71,6 +98,7 @@
7198

7299
.panel.open {
73100
font-size: 40px;
101+
flex: 5;
74102
}
75103

76104
</style>
@@ -105,7 +133,20 @@
105133
</div>
106134

107135
<script>
136+
const panels = document.querySelectorAll('.panel');
137+
138+
const toggleOpen = (event, panel) => {
139+
panel.classList.toggle('open');
140+
}
141+
142+
const toggleActive = (event, panel) => {
143+
if(event.propertyName.includes('flex')){
144+
panel.classList.toggle('open-active');
145+
}
146+
}
108147

148+
panels.forEach(panel => panel.addEventListener('click', (event) => toggleOpen(event, panel)));
149+
panels.forEach(panel => panel.addEventListener('transitionend', (event) => toggleActive(event, panel)));
109150
</script>
110151

111152

0 commit comments

Comments
 (0)