Visitar URL original
Complete · wesbos/JavaScript30@969a8e2 · GitHub
Skip to content

Commit 969a8e2

Browse files
committed
Complete
1 parent 3f8f8ab commit 969a8e2

2 files changed

Lines changed: 51 additions & 145 deletions

File tree

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

Lines changed: 0 additions & 145 deletions
This file was deleted.

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
.panels {
2525
min-height:100vh;
2626
overflow: hidden;
27+
display: flex;
28+
flex: 1;
2729
}
2830

2931
.panel {
@@ -41,6 +43,11 @@
4143
font-size: 20px;
4244
background-size:cover;
4345
background-position:center;
46+
flex: 1;
47+
display: flex;
48+
justify-content: center;
49+
align-items: center;
50+
flex-direction: column;
4451
}
4552

4653

@@ -54,6 +61,31 @@
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+
70+
/*This moves the top words outside of the view*/
71+
.panel > *:first-child {
72+
transform: translateY(-100%);
73+
}
74+
75+
/*This moves the bottom words outside of the view*/
76+
.panel > *:last-child {
77+
transform: translateY(100%);
78+
}
79+
80+
/*When the element has the class of open-active it executes the code below.*/
81+
.panel.open-active > *:first-child {
82+
transform: translateY(0);
83+
}
84+
85+
86+
/*When the element has the class of open-active it executes the code below.*/
87+
.panel.open-active > *:last-child {
88+
transform: translateY(0);
5789
}
5890

5991
.panel p {
@@ -68,6 +100,7 @@
68100

69101
.panel.open {
70102
font-size:40px;
103+
flex: 5;
71104
}
72105

73106
.cta {
@@ -107,6 +140,24 @@
107140
</div>
108141

109142
<script>
143+
const panels = document.querySelectorAll('.panel');
144+
145+
function toggleOpen() {
146+
this.classList.toggle('open');
147+
};
148+
149+
// We use .includes('flex') because most browsers use flex-grow but safari just uses flex. So this fixes that problem.
150+
function toggleActive (e) {
151+
if (e.propertyName.includes('flex')){
152+
this.classList.toggle('open-active');
153+
}
154+
};
155+
156+
panels.forEach(panel => panel.addEventListener('click', toggleOpen));
157+
158+
panels.forEach(panel => panel.addEventListener('transitionend', toggleActive));
159+
160+
console.log(panels);
110161

111162
</script>
112163

0 commit comments

Comments
 (0)