Skip to content

Commit ea80158

Browse files
committed
wesbos#5 - Flex Panel Gallery
1 parent 0312639 commit ea80158

File tree

1 file changed

+75
-15
lines changed

1 file changed

+75
-15
lines changed

05 - Flex Panel Gallery/index-START.html

+75-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset="UTF-8">
56
<title>Flex Panels 💪</title>
67
<link href='https://fonts.googleapis.com/css?family=Amatic+SC' rel='stylesheet' type='text/css'>
78
</head>
9+
810
<body>
911
<style>
1012
html {
@@ -14,48 +16,90 @@
1416
font-size: 20px;
1517
font-weight: 200;
1618
}
17-
19+
1820
body {
1921
margin: 0;
2022
}
21-
22-
*, *:before, *:after {
23+
24+
*,
25+
*:before,
26+
*:after {
2327
box-sizing: inherit;
2428
}
2529

2630
.panels {
2731
min-height: 100vh;
2832
overflow: hidden;
33+
display: flex;
2934
}
3035

3136
.panel {
3237
background: #6B0F9C;
33-
box-shadow: inset 0 0 0 5px rgba(255,255,255,0.1);
38+
box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.1);
3439
color: white;
3540
text-align: center;
3641
align-items: center;
3742
/* Safari transitionend event.propertyName === flex */
3843
/* Chrome + FF transitionend event.propertyName === flex-grow */
3944
transition:
40-
font-size 0.7s cubic-bezier(0.61,-0.19, 0.7,-0.11),
41-
flex 0.7s cubic-bezier(0.61,-0.19, 0.7,-0.11),
45+
font-size 0.7s cubic-bezier(0.61, -0.19, 0.7, -0.11),
46+
flex 0.7s cubic-bezier(0.61, -0.19, 0.7, -0.11),
4247
background 0.2s;
4348
font-size: 20px;
4449
background-size: cover;
4550
background-position: center;
51+
flex: 1;
52+
justify-content: center;
53+
align-items: center;
54+
display: flex;
55+
flex-direction: column;
56+
}
57+
58+
.panel1 {
59+
background-image: url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500);
4660
}
4761

48-
.panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); }
49-
.panel2 { background-image:url(https://source.unsplash.com/rFKUFzjPYiQ/1500x1500); }
50-
.panel3 { background-image:url(https://images.unsplash.com/photo-1465188162913-8fb5709d6d57?ixlib=rb-0.3.5&q=80&fm=jpg&crop=faces&cs=tinysrgb&w=1500&h=1500&fit=crop&s=967e8a713a4e395260793fc8c802901d); }
51-
.panel4 { background-image:url(https://source.unsplash.com/ITjiVXcwVng/1500x1500); }
52-
.panel5 { background-image:url(https://source.unsplash.com/3MNzGlQM7qs/1500x1500); }
62+
.panel2 {
63+
background-image: url(https://source.unsplash.com/rFKUFzjPYiQ/1500x1500);
64+
}
65+
66+
.panel3 {
67+
background-image: url(https://images.unsplash.com/photo-1465188162913-8fb5709d6d57?ixlib=rb-0.3.5&q=80&fm=jpg&crop=faces&cs=tinysrgb&w=1500&h=1500&fit=crop&s=967e8a713a4e395260793fc8c802901d);
68+
}
69+
70+
.panel4 {
71+
background-image: url(https://source.unsplash.com/ITjiVXcwVng/1500x1500);
72+
}
73+
74+
.panel5 {
75+
background-image: url(https://source.unsplash.com/3MNzGlQM7qs/1500x1500);
76+
}
5377

5478
/* Flex Children */
55-
.panel > * {
79+
.panel>* {
5680
margin: 0;
5781
width: 100%;
5882
transition: transform 0.5s;
83+
flex: 1 0 auto;
84+
display: flex;
85+
justify-content: center;
86+
align-content: center;
87+
}
88+
89+
.panel>*:first-child {
90+
transform: translateY(-100%);
91+
}
92+
93+
.panel.open-active>*:first-child {
94+
transform: translateY(0);
95+
}
96+
97+
.panel>*:last-child {
98+
transform: translateY(100%);
99+
}
100+
101+
.panel.open-active>*:last-child {
102+
transform: translateY(0);
59103
}
60104

61105
.panel p {
@@ -64,15 +108,15 @@
64108
text-shadow: 0 0 4px rgba(0, 0, 0, 0.72), 0 0 14px rgba(0, 0, 0, 0.45);
65109
font-size: 2em;
66110
}
67-
111+
68112
.panel p:nth-child(2) {
69113
font-size: 4em;
70114
}
71115

72116
.panel.open {
73117
font-size: 40px;
118+
flex: 5;
74119
}
75-
76120
</style>
77121

78122

@@ -105,10 +149,26 @@
105149
</div>
106150

107151
<script>
152+
let panels = document.querySelectorAll('.panel');
153+
154+
function toggleOpen() {
155+
this.classList.toggle('open');
156+
}
157+
158+
function toggleActive(e) {
159+
// console.log(e.propertyName);
160+
if (e.propertyName.includes('flex')) {
161+
this.classList.toggle('open-active');
162+
}
163+
}
164+
165+
panels.forEach(panel => panel.addEventListener('click', toggleOpen));
166+
panels.forEach(panel => panel.addEventListener('transitionend', toggleActive));
108167

109168
</script>
110169

111170

112171

113172
</body>
114-
</html>
173+
174+
</html>

0 commit comments

Comments
 (0)