|
24 | 24 | .panels { |
25 | 25 | min-height:100vh; |
26 | 26 | overflow: hidden; |
| 27 | + display: flex; |
| 28 | + flex: 1; |
27 | 29 | } |
28 | 30 |
|
29 | 31 | .panel { |
|
41 | 43 | font-size: 20px; |
42 | 44 | background-size:cover; |
43 | 45 | background-position:center; |
| 46 | + flex: 1; |
| 47 | + display: flex; |
| 48 | + justify-content: center; |
| 49 | + align-items: center; |
| 50 | + flex-direction: column; |
44 | 51 | } |
45 | 52 |
|
46 | 53 |
|
|
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 | + |
| 70 | + /*This moves the top words outside of the view*/ |
| 71 | + .panel > *:first-child { |
| 72 | + transform: translateY(-100%); |
| 73 | + } |
| 74 | + |
| 75 | + /*This moves the bottom words outside of the view*/ |
| 76 | + .panel > *:last-child { |
| 77 | + transform: translateY(100%); |
| 78 | + } |
| 79 | + |
| 80 | + /*When the element has the class of open-active it executes the code below.*/ |
| 81 | + .panel.open-active > *:first-child { |
| 82 | + transform: translateY(0); |
| 83 | + } |
| 84 | + |
| 85 | + |
| 86 | + /*When the element has the class of open-active it executes the code below.*/ |
| 87 | + .panel.open-active > *:last-child { |
| 88 | + transform: translateY(0); |
57 | 89 | } |
58 | 90 |
|
59 | 91 | .panel p { |
|
68 | 100 |
|
69 | 101 | .panel.open { |
70 | 102 | font-size:40px; |
| 103 | + flex: 5; |
71 | 104 | } |
72 | 105 |
|
73 | 106 | .cta { |
|
107 | 140 | </div> |
108 | 141 |
|
109 | 142 | <script> |
| 143 | + const panels = document.querySelectorAll('.panel'); |
| 144 | + |
| 145 | + function toggleOpen() { |
| 146 | + this.classList.toggle('open'); |
| 147 | + }; |
| 148 | + |
| 149 | + // We use .includes('flex') because most browsers use flex-grow but safari just uses flex. So this fixes that problem. |
| 150 | + function toggleActive (e) { |
| 151 | + if (e.propertyName.includes('flex')){ |
| 152 | + this.classList.toggle('open-active'); |
| 153 | + } |
| 154 | + }; |
| 155 | + |
| 156 | + panels.forEach(panel => panel.addEventListener('click', toggleOpen)); |
| 157 | + |
| 158 | + panels.forEach(panel => panel.addEventListener('transitionend', toggleActive)); |
| 159 | + |
| 160 | + console.log(panels); |
110 | 161 |
|
111 | 162 | </script> |
112 | 163 |
|
|
0 commit comments