|
24 | 24 | .panels { |
25 | 25 | min-height:100vh; |
26 | 26 | overflow: hidden; |
| 27 | + display: flex; |
27 | 28 | } |
28 | 29 |
|
29 | 30 | .panel { |
| 31 | + flex: 1; |
30 | 32 | background:#6B0F9C; |
31 | 33 | box-shadow:inset 0 0 0 5px rgba(255,255,255,0.1); |
32 | 34 | color:white; |
|
41 | 43 | font-size: 20px; |
42 | 44 | background-size:cover; |
43 | 45 | background-position:center; |
| 46 | + justify-content: center; |
| 47 | + align-items: center; |
| 48 | + display: flex; |
| 49 | + flex-direction: column; |
44 | 50 | } |
45 | 51 |
|
46 | 52 |
|
|
50 | 56 | .panel4 { background-image:url(https://source.unsplash.com/ITjiVXcwVng/1500x1500); } |
51 | 57 | .panel5 { background-image:url(https://source.unsplash.com/3MNzGlQM7qs/1500x1500); } |
52 | 58 |
|
| 59 | +/* Flex Children */ |
53 | 60 | .panel > * { |
54 | 61 | margin:0; |
55 | 62 | width: 100%; |
56 | 63 | transition:transform 0.5s; |
| 64 | + flex: 1 0 auto; |
| 65 | + display: flex; |
| 66 | + justify-content: center; |
| 67 | + align-items: center; |
| 68 | + } |
| 69 | + .panel > *:first-child { |
| 70 | + transform: translateY(-100%); |
| 71 | + } |
| 72 | + .panel.open-active > *:first-child { |
| 73 | + transform: translateY(0); |
| 74 | + } |
| 75 | + |
| 76 | + .panel > *:last-child { |
| 77 | + transform: translateY(100%); |
| 78 | + } |
| 79 | + .panel.open-active > *:last-child { |
| 80 | + transform: translateY(0); |
57 | 81 | } |
58 | | - |
59 | 82 | .panel p { |
60 | 83 | text-transform: uppercase; |
61 | 84 | font-family: 'Amatic SC', cursive; |
|
68 | 91 |
|
69 | 92 | .panel.open { |
70 | 93 | font-size:40px; |
| 94 | + flex: 5; |
71 | 95 | } |
72 | 96 |
|
73 | 97 | .cta { |
|
107 | 131 | </div> |
108 | 132 |
|
109 | 133 | <script> |
| 134 | + const panels = document.querySelectorAll('.panel'); |
| 135 | + |
| 136 | + function toggleOpen() { |
| 137 | + if (this.classList.contains('open')) { |
| 138 | + //closing an open panel |
| 139 | + this.classList.remove('open'); |
| 140 | + } else { |
| 141 | + //clicking another panel that isn't currently open |
| 142 | + panels.forEach(panel => panel.classList.remove('open')); |
| 143 | + this.classList.toggle('open'); |
| 144 | + } |
| 145 | + } |
110 | 146 |
|
| 147 | + function toggleActive(e) { |
| 148 | + if(e.propertyName.includes('flex')) { |
| 149 | + this.classList.toggle('open-active'); |
| 150 | + } |
| 151 | + } |
| 152 | + panels.forEach(panel => panel.addEventListener('click',toggleOpen)); |
| 153 | + panels.forEach(panel => panel.addEventListener('transitionend',toggleActive)); |
111 | 154 | </script> |
112 | 155 |
|
113 | 156 |
|
|
0 commit comments