|
1 | 1 | <!DOCTYPE html> |
2 | 2 | <html lang="en"> |
| 3 | + |
3 | 4 | <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'> |
| 5 | + <meta charset="UTF-8"> |
| 6 | + <title>Flex Panels 💪</title> |
| 7 | + <link href='https://fonts.googleapis.com/css?family=Amatic+SC' rel='stylesheet' type='text/css'> |
7 | 8 | </head> |
| 9 | + |
8 | 10 | <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 | | - body { |
18 | | - margin: 0; |
19 | | - } |
20 | | - *, *:before, *:after { |
21 | | - box-sizing: inherit; |
22 | | - } |
23 | | - |
24 | | - .panels { |
25 | | - min-height:100vh; |
26 | | - overflow: hidden; |
27 | | - } |
28 | | - |
29 | | - .panel { |
30 | | - background:#6B0F9C; |
31 | | - box-shadow:inset 0 0 0 5px rgba(255,255,255,0.1); |
32 | | - color:white; |
33 | | - text-align: center; |
34 | | - align-items:center; |
35 | | - /* Safari transitionend event.propertyName === flex */ |
36 | | - /* Chrome + FF transitionend event.propertyName === flex-grow */ |
37 | | - transition: |
38 | | - font-size 0.7s cubic-bezier(0.61,-0.19, 0.7,-0.11), |
39 | | - flex 0.7s cubic-bezier(0.61,-0.19, 0.7,-0.11), |
40 | | - background 0.2s; |
41 | | - font-size: 20px; |
42 | | - background-size:cover; |
43 | | - background-position:center; |
44 | | - } |
45 | | - |
46 | | - |
47 | | - .panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); } |
48 | | - .panel2 { background-image:url(https://source.unsplash.com/1CD3fd8kHnE/1500x1500); } |
49 | | - .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); } |
50 | | - .panel4 { background-image:url(https://source.unsplash.com/ITjiVXcwVng/1500x1500); } |
51 | | - .panel5 { background-image:url(https://source.unsplash.com/3MNzGlQM7qs/1500x1500); } |
52 | | - |
53 | | - .panel > * { |
54 | | - margin:0; |
55 | | - width: 100%; |
56 | | - transition:transform 0.5s; |
57 | | - } |
58 | | - |
59 | | - .panel p { |
60 | | - text-transform: uppercase; |
61 | | - font-family: 'Amatic SC', cursive; |
62 | | - text-shadow:0 0 4px rgba(0, 0, 0, 0.72), 0 0 14px rgba(0, 0, 0, 0.45); |
63 | | - font-size: 2em; |
64 | | - } |
65 | | - .panel p:nth-child(2) { |
66 | | - font-size: 4em; |
67 | | - } |
68 | | - |
69 | | - .panel.open { |
70 | | - font-size:40px; |
71 | | - } |
72 | | - |
73 | | - .cta { |
74 | | - color:white; |
75 | | - text-decoration: none; |
76 | | - } |
77 | | - |
78 | | - </style> |
79 | | - |
80 | | - |
81 | | - <div class="panels"> |
82 | | - <div class="panel panel1"> |
83 | | - <p>Hey</p> |
84 | | - <p>Let's</p> |
85 | | - <p>Dance</p> |
86 | | - </div> |
87 | | - <div class="panel panel2"> |
88 | | - <p>Give</p> |
89 | | - <p>Take</p> |
90 | | - <p>Receive</p> |
91 | | - </div> |
92 | | - <div class="panel panel3"> |
93 | | - <p>Experience</p> |
94 | | - <p>It</p> |
95 | | - <p>Today</p> |
96 | | - </div> |
97 | | - <div class="panel panel4"> |
98 | | - <p>Give</p> |
99 | | - <p>All</p> |
100 | | - <p>You can</p> |
| 11 | + <style> |
| 12 | + html { |
| 13 | + box-sizing: border-box; |
| 14 | + background: #ffc600; |
| 15 | + font-family: 'helvetica neue'; |
| 16 | + font-size: 20px; |
| 17 | + font-weight: 200; |
| 18 | + } |
| 19 | + |
| 20 | + body { |
| 21 | + margin: 0; |
| 22 | + } |
| 23 | + |
| 24 | + *, |
| 25 | + *:before, |
| 26 | + *:after { |
| 27 | + box-sizing: inherit; |
| 28 | + } |
| 29 | + |
| 30 | + .panels { |
| 31 | + min-height: 100vh; |
| 32 | + overflow: hidden; |
| 33 | + /*z pozycji poziomej zmiana na pionową*/ |
| 34 | + display: flex; |
| 35 | + } |
| 36 | + |
| 37 | + .panel { |
| 38 | + background: #6B0F9C; |
| 39 | + box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.1); |
| 40 | + color: white; |
| 41 | + text-align: center; |
| 42 | + align-items: center; |
| 43 | + /* Safari transitionend event.propertyName === flex */ |
| 44 | + /* Chrome + FF transitionend event.propertyName === flex-grow */ |
| 45 | + /*efekt sprężynowania przy rozszerzaniu panelu*/ |
| 46 | + transition: font-size 0.7s cubic-bezier(0.61, -0.19, 0.7, -0.11), flex 0.7s cubic-bezier(0.61, -0.19, 0.7, -0.11), background 0.2s; |
| 47 | + font-size: 20px; |
| 48 | + background-size: cover; |
| 49 | + background-position: center; |
| 50 | + /*spowoduje rozciągnięcie paneli na szeokość ekranu*/ |
| 51 | + flex: 1; |
| 52 | + justify-content: center; |
| 53 | + align-items: center; |
| 54 | + /*spowoduje przesunięcie napisów z panelu do środka*/ |
| 55 | + display: flex; |
| 56 | + /*zmienia układ napisów panelu na kolumnowy*/ |
| 57 | + flex-direction: column; |
| 58 | + } |
| 59 | + |
| 60 | + .panel1 { |
| 61 | + background-image: url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); |
| 62 | + } |
| 63 | + |
| 64 | + .panel2 { |
| 65 | + background-image: url(https://source.unsplash.com/1CD3fd8kHnE/1500x1500); |
| 66 | + } |
| 67 | + |
| 68 | + .panel3 { |
| 69 | + 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); |
| 70 | + } |
| 71 | + |
| 72 | + .panel4 { |
| 73 | + background-image: url(https://source.unsplash.com/ITjiVXcwVng/1500x1500); |
| 74 | + } |
| 75 | + |
| 76 | + .panel5 { |
| 77 | + background-image: url(https://source.unsplash.com/3MNzGlQM7qs/1500x1500); |
| 78 | + } |
| 79 | + |
| 80 | + .panel>* { |
| 81 | + /*linie pomocnicze*/ |
| 82 | + /*border: 1px solid red;*/ |
| 83 | + margin: 0; |
| 84 | + width: 100%; |
| 85 | + transition: transform 0.5s; |
| 86 | + /*spowoduje rozbicie tekstu w panelach*/ |
| 87 | + flex: 1 0 auto; |
| 88 | + /*układ flex i centralne rozłożenie pojedynczych skladowych napisów z panelu */ |
| 89 | + display: flex; |
| 90 | + align-items: center; |
| 91 | + justify-content: center; |
| 92 | + } |
| 93 | + |
| 94 | + .panel>*:first-child { |
| 95 | + /*powoduje znikanie do góry w osi pionowej pierwszego paragrafu z panelu */ |
| 96 | + transform: translateY(-100%); |
| 97 | + } |
| 98 | + |
| 99 | + .panel.open-active>*:first-child { |
| 100 | + transform: translateY(0); |
| 101 | + } |
| 102 | + |
| 103 | + .panel>*:last-child { |
| 104 | + /*powoduje znikanie do dołu w osi pionowej ostatniego paragrafu z panelu */ |
| 105 | + transform: translateY(100%); |
| 106 | + } |
| 107 | + |
| 108 | + .panel.open-active>*:last-child { |
| 109 | + transform: translateY(0); |
| 110 | + } |
| 111 | + |
| 112 | + .panel p { |
| 113 | + text-transform: uppercase; |
| 114 | + font-family: 'Amatic SC', cursive; |
| 115 | + text-shadow: 0 0 4px rgba(0, 0, 0, 0.72), 0 0 14px rgba(0, 0, 0, 0.45); |
| 116 | + font-size: 2em; |
| 117 | + } |
| 118 | + |
| 119 | + .panel p:nth-child(2) { |
| 120 | + font-size: 4em; |
| 121 | + } |
| 122 | + |
| 123 | + .panel.open { |
| 124 | + /*spowoduje zwiększenie obszaru panelu, na którym aktualnie klikamy*/ |
| 125 | + flex: 5; |
| 126 | + font-size: 40px; |
| 127 | + } |
| 128 | + |
| 129 | + .cta { |
| 130 | + color: white; |
| 131 | + text-decoration: none; |
| 132 | + } |
| 133 | + </style> |
| 134 | + |
| 135 | + |
| 136 | + <div class="panels"> |
| 137 | + <div class="panel panel1"> |
| 138 | + <p>Hey</p> |
| 139 | + <p>Let's</p> |
| 140 | + <p>Dance</p> |
| 141 | + </div> |
| 142 | + <div class="panel panel2"> |
| 143 | + <p>Give</p> |
| 144 | + <p>Take</p> |
| 145 | + <p>Receive</p> |
| 146 | + </div> |
| 147 | + <div class="panel panel3"> |
| 148 | + <p>Experience</p> |
| 149 | + <p>It</p> |
| 150 | + <p>Today</p> |
| 151 | + </div> |
| 152 | + <div class="panel panel4"> |
| 153 | + <p>Give</p> |
| 154 | + <p>All</p> |
| 155 | + <p>You can</p> |
| 156 | + </div> |
| 157 | + <div class="panel panel5"> |
| 158 | + <p>Life</p> |
| 159 | + <p>In</p> |
| 160 | + <p>Motion</p> |
| 161 | + </div> |
101 | 162 | </div> |
102 | | - <div class="panel panel5"> |
103 | | - <p>Life</p> |
104 | | - <p>In</p> |
105 | | - <p>Motion</p> |
106 | | - </div> |
107 | | - </div> |
108 | 163 |
|
109 | | - <script> |
| 164 | + <script> |
| 165 | + const panels = document.querySelectorAll('.panel'); |
| 166 | + |
| 167 | + function toogleOpen() { |
| 168 | + this.classList.toggle('open'); |
| 169 | + } |
110 | 170 |
|
111 | | - </script> |
| 171 | + function toogleActive(e) { |
| 172 | + console.log(e.propertyName); |
| 173 | + //klikając na panel zobaczymy font-size i flex-grow. |
| 174 | + // Safari transitionend event.propertyName === flex |
| 175 | + // Chrome + FF transitionend event.propertyName === flex-grow dlatego nie wystarczy samo dodawanie i odejmowanie klasy open-active. Konieczny jest poniższy zabieg z zastosowaniem if'a: |
| 176 | + if (e.propertyName.includes('flex')) { |
| 177 | + this.classList.toggle('open-active'); |
| 178 | + } |
| 179 | + } |
| 180 | + |
| 181 | + panels.forEach(panel => panel.addEventListener('click', toogleOpen)); |
| 182 | + panels.forEach(panel => panel.addEventListener('transitionend', toogleActive)); |
| 183 | + </script> |
112 | 184 |
|
113 | 185 |
|
114 | 186 |
|
115 | 187 | </body> |
| 188 | + |
116 | 189 | </html> |
0 commit comments