|
24 | 24 | .panels {
|
25 | 25 | min-height:100vh;
|
26 | 26 | overflow: hidden;
|
| 27 | + display: flex; |
27 | 28 | }
|
28 | 29 |
|
29 | 30 | .panel {
|
|
41 | 42 | font-size: 20px;
|
42 | 43 | background-size:cover;
|
43 | 44 | background-position:center;
|
| 45 | + flex: 1; |
| 46 | + justify-content: center; |
| 47 | + align-items: center; |
| 48 | + display: flex; |
| 49 | + flex-direction: column; |
44 | 50 | }
|
45 | 51 |
|
46 | 52 |
|
| 53 | + |
| 54 | + |
47 | 55 | .panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); }
|
48 | 56 | .panel2 { background-image:url(https://source.unsplash.com/1CD3fd8kHnE/1500x1500); }
|
49 | 57 | .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); }
|
|
54 | 62 | margin:0;
|
55 | 63 | width: 100%;
|
56 | 64 | transition:transform 0.5s;
|
| 65 | + |
| 66 | + flex: 1 0 auto; |
| 67 | + display:flex; |
| 68 | + justify-content: center; |
| 69 | + align-items: center; |
| 70 | + } |
| 71 | + |
| 72 | + .panel > *:first-child { |
| 73 | + transform: translateY(-100%); |
| 74 | + } |
| 75 | + |
| 76 | + .panel.open-active > *:first-child { |
| 77 | + transform: translateY(0); |
| 78 | + } |
| 79 | + |
| 80 | + .panel > *:last-child { |
| 81 | + transform: translateY(100%); |
| 82 | + } |
| 83 | + |
| 84 | + .panel.open-active > *:last-child { |
| 85 | + transform: translateY(0); |
57 | 86 | }
|
58 | 87 |
|
59 | 88 | .panel p {
|
|
68 | 97 |
|
69 | 98 | .panel.open {
|
70 | 99 | font-size:40px;
|
| 100 | + flex:5; |
71 | 101 | }
|
72 | 102 |
|
73 | 103 | .cta {
|
|
107 | 137 | </div>
|
108 | 138 |
|
109 | 139 | <script>
|
| 140 | + const panels = document.querySelectorAll('.panel'); |
| 141 | + |
| 142 | + function toggleOpen(){ |
| 143 | + this.classList.toggle('open'); |
| 144 | + } |
| 145 | + |
| 146 | + function toggleActive (e) { |
| 147 | + if (e.propertyName.includes('flex')) { |
| 148 | + this.classList.toggle('open-active'); |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + panels.forEach(function(panel){ |
| 153 | + panel.addEventListener('click',toggleOpen); |
| 154 | + }); |
110 | 155 |
|
| 156 | + panels.forEach(function(panel){ |
| 157 | + panel.addEventListener('transitionend',toggleActive); |
| 158 | + }); |
111 | 159 | </script>
|
112 | 160 |
|
113 | 161 |
|
|
0 commit comments