|
4 | 4 | <meta charset="UTF-8"> |
5 | 5 | <title>Flex Panels 💪</title> |
6 | 6 | <link href='https://fonts.googleapis.com/css?family=Amatic+SC' rel='stylesheet' type='text/css'> |
| 7 | + <link rel="stylesheet" href="style.css" /> |
7 | 8 | </head> |
8 | 9 | <body> |
9 | | - <style> |
10 | | - html { |
11 | | - box-sizing: border-box; |
12 | | - background: #ffc600; |
13 | | - font-family: 'helvetica neue'; |
14 | | - font-size: 20px; |
15 | | - font-weight: 200; |
16 | | - } |
17 | | - |
18 | | - body { |
19 | | - margin: 0; |
20 | | - } |
21 | | - |
22 | | - *, *:before, *:after { |
23 | | - box-sizing: inherit; |
24 | | - } |
25 | | - |
26 | | - .panels { |
27 | | - min-height: 100vh; |
28 | | - overflow: hidden; |
29 | | - } |
30 | | - |
31 | | - .panel { |
32 | | - background: #6B0F9C; |
33 | | - box-shadow: inset 0 0 0 5px rgba(255,255,255,0.1); |
34 | | - color: white; |
35 | | - text-align: center; |
36 | | - align-items: center; |
37 | | - /* Safari transitionend event.propertyName === flex */ |
38 | | - /* Chrome + FF transitionend event.propertyName === flex-grow */ |
39 | | - transition: |
40 | | - font-size 0.7s cubic-bezier(0.61,-0.19, 0.7,-0.11), |
41 | | - flex 0.7s cubic-bezier(0.61,-0.19, 0.7,-0.11), |
42 | | - background 0.2s; |
43 | | - font-size: 20px; |
44 | | - background-size: cover; |
45 | | - background-position: center; |
46 | | - } |
47 | | - |
48 | | - .panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); } |
49 | | - .panel2 { background-image:url(https://source.unsplash.com/rFKUFzjPYiQ/1500x1500); } |
50 | | - .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); } |
51 | | - .panel4 { background-image:url(https://source.unsplash.com/ITjiVXcwVng/1500x1500); } |
52 | | - .panel5 { background-image:url(https://source.unsplash.com/3MNzGlQM7qs/1500x1500); } |
53 | | - |
54 | | - /* Flex Children */ |
55 | | - .panel > * { |
56 | | - margin: 0; |
57 | | - width: 100%; |
58 | | - transition: transform 0.5s; |
59 | | - } |
60 | | - |
61 | | - .panel p { |
62 | | - text-transform: uppercase; |
63 | | - font-family: 'Amatic SC', cursive; |
64 | | - text-shadow: 0 0 4px rgba(0, 0, 0, 0.72), 0 0 14px rgba(0, 0, 0, 0.45); |
65 | | - font-size: 2em; |
66 | | - } |
67 | | - |
68 | | - .panel p:nth-child(2) { |
69 | | - font-size: 4em; |
70 | | - } |
71 | | - |
72 | | - .panel.open { |
73 | | - font-size: 40px; |
74 | | - } |
75 | | - |
76 | | - </style> |
77 | | - |
78 | 10 |
|
79 | 11 | <div class="panels"> |
80 | 12 | <div class="panel panel1"> |
|
105 | 37 | </div> |
106 | 38 |
|
107 | 39 | <script> |
| 40 | + const panels = document.querySelectorAll('.panel'); |
| 41 | + function toggleOpen() { |
| 42 | + this.classList.toggle('open'); |
| 43 | + } |
| 44 | + function toggleOpenActive(e) { |
| 45 | + console.log(e.propertyName); |
| 46 | + if (e.propertyName.includes('flex')) { |
| 47 | + this.classList.toggle('active-open'); |
| 48 | + } |
| 49 | + } |
| 50 | + panels.forEach(panel => panel.addEventListener('click', toggleOpen)); |
| 51 | + panels.forEach(panel => panel.addEventListener('transitionend', toggleOpenActive)); |
108 | 52 |
|
109 | 53 | </script> |
110 | 54 |
|
111 | | - |
112 | | - |
113 | 55 | </body> |
114 | 56 | </html> |
0 commit comments