|
26 | 26 | .panels { |
27 | 27 | min-height: 100vh; |
28 | 28 | overflow: hidden; |
| 29 | + display: flex; |
29 | 30 | } |
30 | 31 |
|
31 | 32 | .panel { |
|
43 | 44 | font-size: 20px; |
44 | 45 | background-size: cover; |
45 | 46 | background-position: center; |
| 47 | + flex: 1; |
| 48 | + display: flex; |
| 49 | + flex-direction: column; |
| 50 | + justify-content: center; |
| 51 | + align-items: center; |
| 52 | + /* border:1px solid rgba(226, 13, 13, 0.45); */ |
46 | 53 | } |
47 | 54 |
|
48 | 55 | .panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); } |
|
56 | 63 | margin: 0; |
57 | 64 | width: 100%; |
58 | 65 | transition: transform 0.5s; |
| 66 | + border:1px solid rgba(226, 13, 13, 0.45); |
| 67 | + flex: 1 0 auto; |
| 68 | + display: flex; |
| 69 | + justify-content: center; |
| 70 | + align-items: center; |
| 71 | + } |
| 72 | + |
| 73 | + /* this moves top panel downwards when toggled */ |
| 74 | + .panel > *:first-child { |
| 75 | + transform: translateY(-100%); |
| 76 | + } |
| 77 | + .panel.open-active > *:first-child { |
| 78 | + transform: translateY(0); |
| 79 | + } |
| 80 | + /* this moves bottom panel upwards when toggled */ |
| 81 | + .panel > *:last-child { |
| 82 | + transform: translateY(100%); |
| 83 | + } |
| 84 | + .panel.open-active > *:last-child { |
| 85 | + transform: translateY(0); |
59 | 86 | } |
60 | 87 |
|
61 | 88 | .panel p { |
|
71 | 98 |
|
72 | 99 | .panel.open { |
73 | 100 | font-size: 40px; |
| 101 | + /* Use up to 5 times of the extra room in flexbox */ |
| 102 | + flex: 5; |
74 | 103 | } |
75 | 104 |
|
76 | 105 | </style> |
|
105 | 134 | </div> |
106 | 135 |
|
107 | 136 | <script> |
| 137 | + function active(e){ |
| 138 | + console.log(e) |
| 139 | + // console.log(e.getClass) |
| 140 | + console.log("active") |
| 141 | + } |
| 142 | + |
| 143 | + function open(){ |
| 144 | + console.log("open") |
| 145 | + } |
108 | 146 |
|
| 147 | + function toggleOpen(){ |
| 148 | + this.classList.toggle('open') |
| 149 | + } |
| 150 | + |
| 151 | + function toggleOpenActive(e){ |
| 152 | + console.log("e.propertyName", e.propertyName) |
| 153 | + if(e.propertyName.includes("flex")){ |
| 154 | + this.classList.toggle('open-active') |
| 155 | + } |
| 156 | + } |
| 157 | + const panels = document.querySelectorAll('.panel') |
| 158 | + panels.forEach(key => key.addEventListener('click', toggleOpen)) |
| 159 | + panels.forEach(key => key.addEventListener('transitionend', toggleOpenActive)) |
109 | 160 | </script> |
110 | 161 |
|
111 | 162 |
|
|
0 commit comments