Skip to content

Commit db94b28

Browse files
committed
JS30 wesbos#5 complete
1 parent 8d5a36c commit db94b28

1 file changed

Lines changed: 150 additions & 97 deletions

File tree

Lines changed: 150 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,167 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8">
5-
<title>Flex Panels 💪</title>
6-
<link href='https://fonts.googleapis.com/css?family=Amatic+SC' rel='stylesheet' type='text/css'>
7-
</head>
8-
<body>
9-
<style>
10-
html {
11-
box-sizing: border-box;
12-
background: #ffc600;
13-
font-family: 'helvetica neue';
14-
font-size: 20px;
15-
font-weight: 200;
16-
}
17-
18-
body {
19-
margin: 0;
20-
}
21-
22-
*, *:before, *:after {
23-
box-sizing: inherit;
24-
}
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Flex Panels 💪</title>
6+
<link
7+
href="https://fonts.googleapis.com/css?family=Amatic+SC"
8+
rel="stylesheet"
9+
type="text/css"
10+
/>
11+
</head>
12+
<body>
13+
<style>
14+
html {
15+
box-sizing: border-box;
16+
background: #ffc600;
17+
font-family: "helvetica neue";
18+
font-size: 20px;
19+
font-weight: 200;
20+
}
2521

26-
.panels {
27-
min-height: 100vh;
28-
overflow: hidden;
29-
}
22+
body {
23+
margin: 0;
24+
}
3025

31-
.panel {
32-
background: #6B0F9C;
33-
box-shadow: inset 0 0 0 5px rgba(255,255,255,0.1);
34-
color: white;
35-
text-align: center;
36-
align-items: center;
37-
/* Safari transitionend event.propertyName === flex */
38-
/* Chrome + FF transitionend event.propertyName === flex-grow */
39-
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),
42-
background 0.2s;
43-
font-size: 20px;
44-
background-size: cover;
45-
background-position: center;
46-
}
26+
*,
27+
*:before,
28+
*:after {
29+
box-sizing: inherit;
30+
}
4731

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); }
32+
.panels {
33+
min-height: 100vh;
34+
overflow: hidden;
35+
display: flex;
36+
}
5337

54-
/* Flex Children */
55-
.panel > * {
56-
margin: 0;
57-
width: 100%;
58-
transition: transform 0.5s;
59-
}
38+
.panel {
39+
background: #6b0f9c;
40+
box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.1);
41+
color: white;
42+
text-align: center;
43+
align-items: center;
44+
/* Safari transitionend event.propertyName === flex */
45+
/* Chrome + FF transitionend event.propertyName === flex-grow */
46+
transition: font-size 0.7s cubic-bezier(0.61, -0.19, 0.7, -0.11),
47+
flex 0.7s cubic-bezier(0.61, -0.19, 0.7, -0.11),
48+
background 0.2s;
49+
font-size: 20px;
50+
background-size: cover;
51+
background-position: center;
52+
flex: 1;
53+
justify-content: center;
54+
align-items: center;
55+
display: flex;
56+
flex-direction: column;
57+
}
6058

61-
.panel p {
62-
text-transform: uppercase;
63-
font-family: 'Amatic SC', cursive;
64-
text-shadow: 0 0 4px rgba(0, 0, 0, 0.72), 0 0 14px rgba(0, 0, 0, 0.45);
65-
font-size: 2em;
66-
}
67-
68-
.panel p:nth-child(2) {
69-
font-size: 4em;
70-
}
59+
.panel1 {
60+
background-image: url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500);
61+
}
62+
.panel2 {
63+
background-image: url(https://source.unsplash.com/rFKUFzjPYiQ/1500x1500);
64+
}
65+
.panel3 {
66+
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);
67+
}
68+
.panel4 {
69+
background-image: url(https://source.unsplash.com/ITjiVXcwVng/1500x1500);
70+
}
71+
.panel5 {
72+
background-image: url(https://source.unsplash.com/3MNzGlQM7qs/1500x1500);
73+
}
7174

72-
.panel.open {
73-
font-size: 40px;
74-
}
75+
/* Flex Children */
76+
.panel > * {
77+
margin: 0;
78+
width: 100%;
79+
transition: transform 0.5s;
80+
flex: 1 0 auto;
81+
display: flex;
82+
justify-content: center;
83+
align-items: center;
84+
}
7585

76-
</style>
86+
.panel > *:first-child {
87+
transform: translateY(-100%);
88+
}
89+
.panel.open-active > *:first-child {
90+
transform: translateY(0);
91+
}
92+
.panel > *:last-child {
93+
transform: translateY(100%);
94+
}
95+
.panel.open-active > *:last-child {
96+
transform: translateY(0);
97+
}
7798

99+
.panel p {
100+
text-transform: uppercase;
101+
font-family: "Amatic SC", cursive;
102+
text-shadow: 0 0 4px rgba(0, 0, 0, 0.72),
103+
0 0 14px rgba(0, 0, 0, 0.45);
104+
font-size: 2em;
105+
}
78106

79-
<div class="panels">
80-
<div class="panel panel1">
81-
<p>Hey</p>
82-
<p>Let's</p>
83-
<p>Dance</p>
84-
</div>
85-
<div class="panel panel2">
86-
<p>Give</p>
87-
<p>Take</p>
88-
<p>Receive</p>
89-
</div>
90-
<div class="panel panel3">
91-
<p>Experience</p>
92-
<p>It</p>
93-
<p>Today</p>
94-
</div>
95-
<div class="panel panel4">
96-
<p>Give</p>
97-
<p>All</p>
98-
<p>You can</p>
99-
</div>
100-
<div class="panel panel5">
101-
<p>Life</p>
102-
<p>In</p>
103-
<p>Motion</p>
104-
</div>
105-
</div>
107+
.panel p:nth-child(2) {
108+
font-size: 4em;
109+
}
106110

107-
<script>
111+
.panel.open {
112+
flex: 5;
113+
font-size: 40px;
114+
}
115+
</style>
108116

109-
</script>
117+
<div class="panels">
118+
<div class="panel panel1">
119+
<p>Hey</p>
120+
<p>Let's</p>
121+
<p>Dance</p>
122+
</div>
123+
<div class="panel panel2">
124+
<p>Give</p>
125+
<p>Take</p>
126+
<p>Receive</p>
127+
</div>
128+
<div class="panel panel3">
129+
<p>Experience</p>
130+
<p>It</p>
131+
<p>Today</p>
132+
</div>
133+
<div class="panel panel4">
134+
<p>Give</p>
135+
<p>All</p>
136+
<p>You can</p>
137+
</div>
138+
<div class="panel panel5">
139+
<p>Life</p>
140+
<p>In</p>
141+
<p>Motion</p>
142+
</div>
143+
</div>
110144

145+
<script>
146+
const panels = document.querySelectorAll(".panel");
111147

148+
function toggleOpen() {
149+
this.classList.toggle("open");
150+
}
112151

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

0 commit comments

Comments
 (0)