Skip to content

Commit 33d678d

Browse files
committed
finish flex panels exercise
1 parent acaa2a3 commit 33d678d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

05 - Flex Panel Gallery/index-START.html

Lines changed: 51 additions & 0 deletions
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+
flex: 1;
48+
display: flex;
49+
flex-direction: column;
50+
justify-content: center;
51+
align-items: center;
52+
/* border:1px solid rgba(226, 13, 13, 0.45); */
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+
border:1px solid rgba(226, 13, 13, 0.45);
67+
flex: 1 0 auto;
68+
display: flex;
69+
justify-content: center;
70+
align-items: center;
71+
}
72+
73+
/* this moves top panel downwards when toggled */
74+
.panel > *:first-child {
75+
transform: translateY(-100%);
76+
}
77+
.panel.open-active > *:first-child {
78+
transform: translateY(0);
79+
}
80+
/* this moves bottom panel upwards when toggled */
81+
.panel > *:last-child {
82+
transform: translateY(100%);
83+
}
84+
.panel.open-active > *:last-child {
85+
transform: translateY(0);
5986
}
6087

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

7299
.panel.open {
73100
font-size: 40px;
101+
/* Use up to 5 times of the extra room in flexbox */
102+
flex: 5;
74103
}
75104

76105
</style>
@@ -105,7 +134,29 @@
105134
</div>
106135

107136
<script>
137+
function active(e){
138+
console.log(e)
139+
// console.log(e.getClass)
140+
console.log("active")
141+
}
142+
143+
function open(){
144+
console.log("open")
145+
}
108146

147+
function toggleOpen(){
148+
this.classList.toggle('open')
149+
}
150+
151+
function toggleOpenActive(e){
152+
console.log("e.propertyName", e.propertyName)
153+
if(e.propertyName.includes("flex")){
154+
this.classList.toggle('open-active')
155+
}
156+
}
157+
const panels = document.querySelectorAll('.panel')
158+
panels.forEach(key => key.addEventListener('click', toggleOpen))
159+
panels.forEach(key => key.addEventListener('transitionend', toggleOpenActive))
109160
</script>
110161

111162

0 commit comments

Comments
 (0)