File tree Expand file tree Collapse file tree 5 files changed +85
-1
lines changed
10-hold-shift-and-check-checkboxes Expand file tree Collapse file tree 5 files changed +85
-1
lines changed Original file line number Diff line number Diff line change
1
+ # Hold shift and checkboxes
2
+ Watch this challenge live in [ codepen] ( ) .
Original file line number Diff line number Diff line change
1
+ /*jshint esversion: 6 */
2
+
3
+ ( function ( ) {
4
+
5
+ const checkboxes = document . querySelectorAll ( 'input' ) ;
6
+ checkboxes . forEach ( checkbox => checkbox . addEventListener ( 'click' , handleClick ) ) ;
7
+ let lastChecked ;
8
+
9
+ function handleClick ( e ) {
10
+ let inBetween = false ;
11
+ if ( e . shiftKey && this . checked ) {
12
+
13
+ checkboxes . forEach ( checkbox => {
14
+ if ( this === checkbox || checkbox === lastChecked ) {
15
+ inBetween = ! inBetween ;
16
+ }
17
+
18
+ if ( inBetween ) {
19
+ checkbox . checked = true ;
20
+ }
21
+ } ) ;
22
+ }
23
+
24
+ lastChecked = this ;
25
+ }
26
+
27
+ } ) ( ) ;
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < meta charset ="utf-8 ">
5
+ < title > Hold shift and checkboxes</ title >
6
+ < link rel ="stylesheet " href ="style.css " media ="screen " title ="no title ">
7
+ </ head >
8
+ < body >
9
+ < ul class ="list ">
10
+ < li > < input type ="checkbox "> < label > Task 1</ label > </ li >
11
+ < li > < input type ="checkbox "> < label > Task 2</ label > </ li >
12
+ < li > < input type ="checkbox "> < label > Task 3</ label > </ li >
13
+ < li > < input type ="checkbox "> < label > Task 4</ label > </ li >
14
+ < li > < input type ="checkbox "> < label > Task 5</ label > </ li >
15
+ < li > < input type ="checkbox "> < label > Task 6</ label > </ li >
16
+ < li > < input type ="checkbox "> < label > Task 7</ label > </ li >
17
+ < li > < input type ="checkbox "> < label > Task 8</ label > </ li >
18
+ </ ul >
19
+
20
+ < script type ="text/javascript " src ="app.js "> </ script >
21
+ </ body >
22
+ </ html >
Original file line number Diff line number Diff line change
1
+ body {
2
+ font-family : sans-serif;
3
+ font-size : 1.2em ;
4
+ color : # 383838 ;
5
+ background-color : # e7e4e4 ;
6
+ margin : 0 ;
7
+ min-height : 100vh ;
8
+ display : flex;
9
+ flex-direction : column;
10
+ align-items : center;
11
+ }
12
+
13
+ .list {
14
+ list-style : none;
15
+ padding-left : 0 ;
16
+ }
17
+
18
+ li {
19
+ margin : .8em ;
20
+ width : 15em ;
21
+ }
22
+
23
+ input [type = checkbox ] {
24
+ margin : 1em ;
25
+ }
26
+ input [type = checkbox ]: checked + label {
27
+ text-decoration : line-through;
28
+ }
29
+
30
+ label {
31
+ margin : 1em ;
32
+
33
+ }
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ My goal is simply to learn the basics by doing many simple things rather than st
14
14
7 . [x] [ Array Cardio II] ( ./07-array-cardio-ii ) - [ Codepen] ( http://codepen.io/pouyio/pen/eBxVPr?editors=1111 )
15
15
8 . [x] [ Fun with HTML5 Canvas] ( ./08-fun-with-HTML5-canvas ) - [ Codepen] ( http://codepen.io/pouyio/full/xRBqNL/ )
16
16
9 . [x] [ Dev Tools Domination] ( ./09-must-know-dev-tool-tips ) - [ Codepen] ( http://codepen.io/pouyio/pen/BQbbdp?editors=1111# )
17
- 10 . [ ] Hold Shift and Check Checkboxes
17
+ 10 . [x] [ Hold Shift and Check Checkboxes] ( ./10-hold-shift-and-checkboxes ) - [ Codepen ] ( )
18
18
11 . [ ] Custom Video Player
19
19
12 . [ ] Key Sequence Detection
20
20
13 . [ ] Slide in on Scroll
You can’t perform that action at this time.
0 commit comments