-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
103 lines (82 loc) · 2.46 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const log = (x) => {console.log(x)};
const leftArrow = document.querySelector('.left');
const rightArrow = document.querySelector('.right');
const slider = document.querySelector('.slider');
let images = document.querySelectorAll('.images');
const bottom = document.querySelector('.bottom');
const body = document.querySelector('body');
let lengthImg = images.length;
let sliderCounter = 1;
//Bottom buttons
//For / creating buttons on bottom div
for (let i = 0; i < lengthImg; i++) {
const div = document.createElement("div");
div.className = "button";
bottom.appendChild(div);
}
const buttons = document.querySelectorAll('.button');
buttons[0].style.backgroundColor = "white";
const resetBgButtons = () =>{
buttons.forEach((button) => {
button.style.backgroundColor = "transparent";
});
}
buttons.forEach((button, i) => {
button.addEventListener("click", ()=>{
resetBgButtons();
slider.style.transform = `translateX(-${i * 900}px)`;
sliderCounter = i + 1;
changeBgColor();
button.style.backgroundColor = "white";
})
});
const changeColorButton = ()=>{
resetBgButtons();
buttons[sliderCounter-1].style.backgroundColor = "white";
}
//Slider Function
const nextSlide = () => {
slider.style.transform = `translateX(-${sliderCounter * 900}px)`;
sliderCounter++;
};
const prevSlide = () => {
slider.style.transform = `translateX(-${(sliderCounter - 2) * 900}px)`;
sliderCounter--;
};
const startSlide = () => {
slider.style.transform = `translateX(0px)`;
sliderCounter = 1;
};
const lastSlide = () => {
slider.style.transform = `translateX(-${(lengthImg - 1) * 900}px)`;
sliderCounter = lengthImg;
};
// Arrow Clicks
rightArrow.addEventListener("click", () => {
sliderCounter < lengthImg ? nextSlide() : startSlide();
changeBgColor();
changeColorButton();
});
leftArrow.addEventListener("click", () => {
sliderCounter > 1 ? prevSlide() : lastSlide()
changeBgColor()
changeColorButton();
});
// Background Color
const changeBgColor = () => {
if (sliderCounter == 1) {
body.style.background = "#091a50";
}
else if (sliderCounter == 2) {
body.style.background = "#001a2b";
}
else if (sliderCounter == 3) {
body.style.background = "#001b30";
}
else if (sliderCounter == 4) {
body.style.background = "#0f1730";
}
else if (sliderCounter == 5) {
body.style.background = "#161616";
}
}