|
24 | 24 | .panels {
|
25 | 25 | min-height:100vh;
|
26 | 26 | overflow: hidden;
|
| 27 | + display: flex; |
| 28 | + flex-direction: row; |
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 | + justify-content: center; |
| 48 | + align-items: center; |
| 49 | + display: flex; |
| 50 | + flex-direction: column; |
44 | 51 | }
|
45 | 52 |
|
46 |
| - |
47 |
| - .panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); } |
48 |
| - .panel2 { background-image:url(https://source.unsplash.com/rFKUFzjPYiQ/1500x1500); } |
49 |
| - .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); } |
50 |
| - .panel4 { background-image:url(https://source.unsplash.com/ITjiVXcwVng/1500x1500); } |
51 |
| - .panel5 { background-image:url(https://source.unsplash.com/3MNzGlQM7qs/1500x1500); } |
| 53 | + /* hat tip: https://source.unsplash.com */ |
| 54 | + .panel1 { background-image:url('https://source.unsplash.com/1500x1500/?hawaii'); } |
| 55 | + .panel2 { background-image:url('https://source.unsplash.com/1500x1500/?bali'); } |
| 56 | + .panel3 { background-image:url('https://source.unsplash.com/1500x1500/?tahiti'); } |
| 57 | + .panel4 { background-image:url('https://source.unsplash.com/1500x1500/?fiji'); } |
| 58 | + .panel5 { background-image:url('https://source.unsplash.com/1500x1500/?bermuda'); } |
52 | 59 |
|
53 | 60 | .panel > * {
|
54 |
| - margin:0; |
| 61 | + margin: 0; |
55 | 62 | width: 100%;
|
56 |
| - transition:transform 0.5s; |
| 63 | + transition: transform 0.5s; |
| 64 | + /* border: 1px solid red; */ |
| 65 | + flex: 1 0 auto; |
| 66 | + display: flex; |
| 67 | + justify-content: center; |
| 68 | + align-items: center; |
| 69 | + } |
| 70 | + |
| 71 | + .panel > *:first-child { |
| 72 | + transform: translateY(-100%); |
| 73 | + } |
| 74 | + .panel.open-active > *:first-child { |
| 75 | + transform: translateY(0); |
| 76 | + } |
| 77 | + |
| 78 | + .panel > *:last-child { |
| 79 | + transform: translateY(100%); |
| 80 | + } |
| 81 | + .panel.open-active > *:last-child { |
| 82 | + transform: translateY(0); |
57 | 83 | }
|
58 | 84 |
|
59 | 85 | .panel p {
|
|
68 | 94 |
|
69 | 95 | .panel.open {
|
70 | 96 | font-size:40px;
|
| 97 | + flex: 5; |
71 | 98 | }
|
72 | 99 |
|
73 | 100 | </style>
|
|
102 | 129 | </div>
|
103 | 130 |
|
104 | 131 | <script>
|
| 132 | + const panels = document.querySelectorAll('.panel'); |
| 133 | + |
| 134 | + function toggleOpen() { |
| 135 | + this.classList.toggle('open'); |
| 136 | + } |
| 137 | + function toggleActive(e) { |
| 138 | + // console.log(e.propertyName); |
| 139 | + |
| 140 | + const propName = e.propertyName; |
| 141 | + |
| 142 | + if (propName.includes('flex')) { |
| 143 | + this.classList.toggle('open-active'); |
| 144 | + } |
| 145 | + |
| 146 | + // this.classList.toggle('.open-active'); |
| 147 | + } |
| 148 | + |
| 149 | + panels.forEach(panel => panel.addEventListener('click', toggleOpen)); |
| 150 | + panels.forEach(panel => panel.addEventListener('transitionend', toggleActive)); |
105 | 151 |
|
106 | 152 | </script>
|
107 | 153 |
|
|
0 commit comments