Skip to content

Commit 8412f3a

Browse files
committed
15 - Slider JS - Button Approach
1 parent 703d6b9 commit 8412f3a

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

15-slider/setup/app.js

+21-4
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,30 @@ prevBtn.addEventListener("click", function () {
1919
});
2020

2121
function carousel() {
22-
if (counter > slides.length - 1) {
23-
counter = 0;
22+
/* Working with Slides */
23+
// if (counter > slides.length - 1) {
24+
// counter = 0;
25+
// }
26+
// if (counter < 0) {
27+
// counter = slides.length - 1;
28+
// }
29+
30+
/* Working with Buttons */
31+
if (counter < slides.length - 1) {
32+
nextBtn.style.display = "block";
33+
} else {
34+
nextBtn.style.display = "none";
2435
}
25-
if (counter < 0) {
26-
counter = slides.length - 1;
36+
37+
if (counter > 0) {
38+
prevBtn.style.display = "block";
39+
} else {
40+
prevBtn.style.display = "none";
2741
}
42+
2843
slides.forEach(function (slide) {
2944
slide.style.transform = `translateX(-${counter * 100}%)`;
3045
});
3146
}
47+
48+
prevBtn.style.display = "none";

0 commit comments

Comments
 (0)