Skip to content

Commit 16fc0fb

Browse files
committed
keep moving forward
1 parent 3b3f822 commit 16fc0fb

File tree

3 files changed

+111
-4
lines changed

3 files changed

+111
-4
lines changed

steps/index.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
</div>
2323
</div>
2424

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>
2729

2830
<script src="./script.js"></script>
2931
</body>

steps/script.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
}

steps/style.css

+39-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
}
66

77

8+
:root {
9+
--line-border-fill: #3498db;
10+
--line-border-empty: #e0e0e0;
11+
12+
}
13+
814

915
body {
1016
display: flex;
@@ -31,7 +37,7 @@ body {
3137

3238
.progress-container::before {
3339
content: '';
34-
background-color: #e0e0e0;
40+
background-color: var(--line-border-empty);
3541
position: absolute;
3642
top: 50%;
3743
left: 0;
@@ -43,7 +49,7 @@ body {
4349

4450

4551
.progress {
46-
background-color: #3498db;
52+
background-color: var(--line-border-fill);
4753
position: absolute;
4854
top: 50%;
4955
left: 0;
@@ -69,4 +75,35 @@ body {
6975

7076
.circle.active {
7177
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;
72109
}

0 commit comments

Comments
 (0)