|
3 | 3 | <head> |
4 | 4 | <meta charset="UTF-8"> |
5 | 5 | <title>Flex Panels 💪</title> |
6 | | - <link href='https://fonts.googleapis.com/css?family=Amatic+SC' rel='stylesheet' type='text/css'> |
| 6 | + <link href="https://fonts.googleapis.com/css?family=Amatic+SC" rel="stylesheet" type="text/css"> |
7 | 7 | </head> |
8 | 8 | <body> |
9 | 9 | <style> |
|
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 |
|
|
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 Items */ |
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; |
57 | 68 | } |
58 | 69 |
|
| 70 | + .panel > *:first-child { transform: translateY(-100%); } |
| 71 | + .panel.open-active > *:first-child { transform: translateY(0);} |
| 72 | + .panel > *:last-child { transform: translateY(100%); } |
| 73 | + .panel.open-active > *:last-child { transform: translateY(0);} |
59 | 74 | .panel p { |
60 | 75 | text-transform: uppercase; |
61 | 76 | font-family: 'Amatic SC', cursive; |
|
68 | 83 |
|
69 | 84 | .panel.open { |
70 | 85 | font-size:40px; |
| 86 | + flex: 5; |
71 | 87 | } |
72 | 88 |
|
73 | 89 | .cta { |
|
107 | 123 | </div> |
108 | 124 |
|
109 | 125 | <script> |
110 | | - |
| 126 | + const panels = document.querySelectorAll('.panel'); |
| 127 | + |
| 128 | + function toggleOpen() { |
| 129 | + this.classList.toggle('open'); |
| 130 | + console.log('hello'); |
| 131 | + } |
| 132 | + function toggleActive(e) { |
| 133 | + if(e.propertyName.includes('flex')){ |
| 134 | + this.classList.toggle('open-active'); |
| 135 | + } |
| 136 | + } |
| 137 | + panels.forEach(panel => panel.addEventListener('click', toggleOpen)); |
| 138 | + panels.forEach(panel => panel.addEventListener('transitionend', toggleActive)); |
111 | 139 | </script> |
112 | 140 |
|
113 | 141 |
|
|
0 commit comments