|
3 | 3 | <head> |
4 | 4 | <meta charset="UTF-8"> |
5 | 5 | <title>Hold Shift to Check Multiple Checkboxes</title> |
6 | | - <link rel="icon" href="https://fav.farm/✅" /> |
| 6 | + <link rel="icon" href="https://fav.farm/🔥" /> |
7 | 7 | </head> |
8 | 8 | <body> |
9 | 9 | <style> |
10 | 10 |
|
11 | 11 | html { |
12 | | - font-family: sans-serif; |
13 | | - background: #ffc600; |
| 12 | + font-family:Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif; |
| 13 | + background: #53c5c5; |
14 | 14 | } |
15 | 15 |
|
16 | 16 | .inbox { |
|
27 | 27 | border-bottom: 1px solid #F1F1F1; |
28 | 28 | } |
29 | 29 |
|
| 30 | + button { |
| 31 | + display: block; |
| 32 | + margin: 10px auto; |
| 33 | + } |
| 34 | + |
| 35 | + button:hover { |
| 36 | + color:#53c5c5; |
| 37 | + background-color: black; |
| 38 | + } |
| 39 | + |
30 | 40 | .item:last-child { |
31 | 41 | border-bottom: 0; |
32 | 42 | } |
33 | 43 |
|
34 | | - |
35 | 44 | input:checked + p { |
36 | | - background: #F9F9F9; |
| 45 | + background: #c9c7c7; |
37 | 46 | text-decoration: line-through; |
38 | 47 | } |
39 | 48 |
|
|
46 | 55 | padding: 20px; |
47 | 56 | transition: background 0.2s; |
48 | 57 | flex: 1; |
49 | | - font-family: 'helvetica neue'; |
| 58 | + font-family:'helvetica neue'; |
50 | 59 | font-size: 20px; |
51 | 60 | font-weight: 200; |
52 | 61 | border-left: 1px solid #D1E2FF; |
|
55 | 64 | <!-- |
56 | 65 | The following is a common layout you would see in an email client. |
57 | 66 |
|
58 | | - When a user clicks a checkbox, holds Shift, and then clicks another checkbox a few rows down, all the checkboxes in-between those two checkboxes should be checked. |
| 67 | + When a user clicks a checkbox, holds Shift, and then clicks another checkbox a few rows down, all the checkboxes inbetween those two checkboxes should be checked. |
59 | 68 |
|
60 | 69 | --> |
61 | 70 | <div class="inbox"> |
62 | 71 | <div class="item"> |
63 | 72 | <input type="checkbox"> |
64 | | - <p>This is an inbox layout.</p> |
| 73 | + <p>🗂️ This is an inbox layout.</p> |
65 | 74 | </div> |
66 | 75 | <div class="item"> |
67 | 76 | <input type="checkbox"> |
68 | | - <p>Check one item</p> |
| 77 | + <p>🗂️ Check one item</p> |
69 | 78 | </div> |
70 | 79 | <div class="item"> |
71 | 80 | <input type="checkbox"> |
72 | | - <p>Hold down your Shift key</p> |
| 81 | + <p>🗂️ Hold down your Shift key</p> |
73 | 82 | </div> |
74 | 83 | <div class="item"> |
75 | 84 | <input type="checkbox"> |
76 | | - <p>Check a lower item</p> |
| 85 | + <p>🗂️ Check a lower item</p> |
77 | 86 | </div> |
78 | 87 | <div class="item"> |
79 | 88 | <input type="checkbox"> |
80 | | - <p>Everything in between should also be set to checked</p> |
| 89 | + <p>🗂️ Everything in between should also be set to checked</p> |
81 | 90 | </div> |
82 | 91 | <div class="item"> |
83 | 92 | <input type="checkbox"> |
84 | | - <p>Try do it without any libraries</p> |
| 93 | + <p>🗂️ Try to do it without any libraries</p> |
85 | 94 | </div> |
86 | 95 | <div class="item"> |
87 | 96 | <input type="checkbox"> |
88 | | - <p>Just regular JavaScript</p> |
| 97 | + <p>🗂️ Just regular JavaScript</p> |
89 | 98 | </div> |
90 | 99 | <div class="item"> |
91 | 100 | <input type="checkbox"> |
92 | | - <p>Good Luck!</p> |
| 101 | + <p>🗂️ Good Luck!</p> |
93 | 102 | </div> |
94 | 103 | <div class="item"> |
95 | 104 | <input type="checkbox"> |
96 | | - <p>Don't forget to tweet your result!</p> |
| 105 | + <p>🗂️ Don't forget to tweet your result!</p> |
| 106 | + </div> |
| 107 | + <div class="item"> |
| 108 | + <button id="deselect">Deselect All</button> |
97 | 109 | </div> |
98 | 110 | </div> |
| 111 | + |
99 | 112 |
|
100 | 113 | <script> |
101 | | -const checkboxes = document.querySelectorAll('.inbox input[type="checkbox"]'); |
| 114 | +const checkboxes = document.querySelectorAll('.inbox [type="checkbox"]'); |
102 | 115 |
|
103 | 116 | let lastChecked; |
104 | 117 |
|
|
107 | 120 | // AND check that they are checking it |
108 | 121 | let inBetween = false; |
109 | 122 | if (e.shiftKey && this.checked) { |
110 | | - // go ahead and do what we please |
111 | | - // loop over every single checkbox |
| 123 | + // go ahead and do what we please |
| 124 | + // loop over every single checkbox |
112 | 125 | checkboxes.forEach(checkbox => { |
113 | 126 | console.log(checkbox); |
114 | | - if (checkbox === this || checkbox === lastChecked) { |
| 127 | + if(checkbox === this || checkbox === lastChecked) { |
115 | 128 | inBetween = !inBetween; |
116 | 129 | console.log('Starting to check them in between!'); |
117 | 130 | } |
118 | 131 |
|
119 | | - if (inBetween) { |
| 132 | + if(inBetween) { |
120 | 133 | checkbox.checked = true; |
121 | 134 | } |
122 | 135 | }); |
|
125 | 138 | lastChecked = this; |
126 | 139 | } |
127 | 140 |
|
| 141 | +document.querySelector('#deselect').addEventListener('click', () => { |
| 142 | + checkboxes.forEach(checkbox => checkbox.checked = false); |
| 143 | +}); |
| 144 | + |
128 | 145 | checkboxes.forEach(checkbox => checkbox.addEventListener('click', handleCheck)); |
129 | 146 | </script> |
130 | 147 | </body> |
|
0 commit comments