File tree 3 files changed +111
-4
lines changed
3 files changed +111
-4
lines changed Original file line number Diff line number Diff line change 22
22
</ div >
23
23
</ div >
24
24
25
- < button class ="btn " id ="prev " disabled > </ button >
26
- < button class ="btn " id ="next "> </ button >
25
+ < div class ="btnMe ">
26
+ < button class ="btn " id ="prev " disabled > Prev</ button >
27
+ < button class ="btn " id ="next "> Next</ button >
28
+ </ div >
27
29
28
30
< script src ="./script.js "> </ script >
29
31
</ body >
Original file line number Diff line number Diff line change
1
+ const progress = document . getElementById ( 'progress' ) ;
2
+ const prev = document . getElementById ( 'prev' ) ;
3
+ const next = document . getElementById ( 'next' ) ;
4
+ const circles = document . querySelectorAll ( '.circle' ) ;
5
+
6
+
7
+ let currentActive = 1 ;
8
+
9
+
10
+ next . addEventListener ( 'click' , ( ) => {
11
+ currentActive ++
12
+
13
+ if ( currentActive > circles . length ) {
14
+ currentActive = circles . length
15
+ }
16
+
17
+
18
+ update ( )
19
+ } )
20
+
21
+
22
+ prev . addEventListener ( 'click' , ( ) => {
23
+ currentActive --
24
+
25
+ if ( currentActive <= 1 ) {
26
+ currentActive = 1
27
+
28
+ }
29
+
30
+ update ( )
31
+ } )
32
+
33
+
34
+ function update ( ) {
35
+ circles . forEach ( ( circle , index ) => {
36
+ if ( index < currentActive ) {
37
+ circle . classList . add ( 'active' )
38
+ }
39
+ else {
40
+ circle . classList . remove ( 'active' )
41
+ }
42
+ } )
43
+
44
+
45
+ const actives = document . querySelectorAll ( '.active' ) ;
46
+
47
+
48
+ progress . style . width = ( actives . length - 1 ) / ( circles . length - 1 ) * 100 + '%' ;
49
+
50
+
51
+
52
+
53
+
54
+ if ( currentActive === 1 ) {
55
+ prev . disabled = true
56
+ }
57
+ else if ( currentActive === circles . length ) {
58
+ next . disabled = true
59
+ }
60
+ else {
61
+ prev . disabled = false ;
62
+ next . disabled = false ;
63
+ }
64
+
65
+
66
+
67
+
68
+ }
Original file line number Diff line number Diff line change 5
5
}
6
6
7
7
8
+ : root {
9
+ --line-border-fill : # 3498db ;
10
+ --line-border-empty : # e0e0e0 ;
11
+
12
+ }
13
+
8
14
9
15
body {
10
16
display : flex;
31
37
32
38
.progress-container ::before {
33
39
content : '' ;
34
- background-color : # e0e0e0 ;
40
+ background-color : var ( --line-border-empty ) ;
35
41
position : absolute;
36
42
top : 50% ;
37
43
left : 0 ;
43
49
44
50
45
51
.progress {
46
- background-color : # 3498db ;
52
+ background-color : var ( --line-border-fill ) ;
47
53
position : absolute;
48
54
top : 50% ;
49
55
left : 0 ;
@@ -69,4 +75,35 @@ body {
69
75
70
76
.circle .active {
71
77
border-color : # 3498db ;
78
+ }
79
+
80
+ .btn {
81
+ background-color : var (--line-border-fill );
82
+ color : # fff ;
83
+ border : 0 ;
84
+ border-radius : 6px ;
85
+ cursor : pointer;
86
+ font-family : inherit;
87
+ padding : 8px 30px ;
88
+ margin : 5px ;
89
+ font-size : 14px ;
90
+ }
91
+
92
+
93
+ .btn : active {
94
+ transform : scale (0.98 );
95
+ }
96
+
97
+ .btn : focus {
98
+ outline : 0 ;
99
+ }
100
+
101
+
102
+ .btn : disabled {
103
+ background-color : var (--line-border-empty );
104
+ cursor : pointer;
105
+ }
106
+
107
+ .btnMe {
108
+ display : flex;
72
109
}
You can’t perform that action at this time.
0 commit comments