-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
65 lines (61 loc) · 2.26 KB
/
app.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
document.addEventListener("DOMContentLoaded", function () {
const slider = document.querySelector(".slider input");
const dragLine = document.querySelector(".slider .drag-line");
const img = document.querySelector("#slider-photo-2");
const btnMoveLeft = document.querySelector(".drag-line span .box:first-of-type");
const btnMoveRight = document.querySelector(".drag-line span .box:last-of-type");
slider.addEventListener("input", () => {
let sliderVal = slider.value;
dragLine.style.left = sliderVal + "%";
slider.style.left = sliderVal + "%";
img.style.width = sliderVal + "%";
document.documentElement.style.setProperty("--positionThumb", sliderVal + "%");
})
btnMoveLeft.addEventListener("click", () => {
let sliderVal = parseInt(slider.value);
if (window.innerWidth > 576) {
if (sliderVal < 20) {
sliderVal = 0;
} else {
sliderVal -= 20;
}
} else {
if (sliderVal < 25) {
sliderVal = 0;
} else {
sliderVal -= 25;
}
}
slider.value = sliderVal;
dragLine.style.left = sliderVal + "%";
slider.style.left = sliderVal + "%";
img.style.width = sliderVal + "%";
document.documentElement.style.setProperty("--positionThumb", sliderVal + "%");
})
btnMoveRight.addEventListener("click", () => {
let sliderVal = parseInt(slider.value);
if (window.innerWidth > 576) {
if (sliderVal > 80) {
sliderVal = 100;
} else {
sliderVal += 20;
}
} else {
if (sliderVal > 75) {
sliderVal = 100;
} else {
sliderVal += 25;
}
}
slider.value = sliderVal;
dragLine.style.left = sliderVal + "%";
slider.style.left = sliderVal + "%";
img.style.width = sliderVal + "%";
document.documentElement.style.setProperty("--positionThumb", sliderVal + "%");
})
})
window.addEventListener("load", function () {
const loader = document.querySelector("#loader");
loader.className += "hidden";
document.body.classList.remove("overflow");
})