-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
62 lines (59 loc) · 2.24 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
let imgsBox = document.querySelector(".main-img");
let imgs = document.querySelectorAll(".main-img a");
let buttonSlide = document.querySelectorAll("#slideButton");
let isScrolling = false;
buttonSlide.forEach((button) => {
button.addEventListener("click", async () => {
if (isScrolling) return;
isScrolling = true;
const direction = button.className == "left_img_button" ? -1 : 1;
const scrollImg = direction * imgs[0].clientWidth;
imgsBox.scrollBy({ left: scrollImg, behavior: "smooth" });
await new Promise((resolve) => setTimeout(resolve, 1000));
isScrolling = false;
});
});
let imgsBoxB = document.querySelector(".mini_slide-block");
let buttonSlideB = document.querySelectorAll("#slideButton-b");
buttonSlideB.forEach((button) => {
button.addEventListener("click", () => {
const direction = button.className == "left_img_button" ? -1 : 1;
const scrollImg = direction * (imgs[0].clientWidth - 150);
imgsBoxB.scrollBy({ left: scrollImg, behavior: "smooth" });
});
});
let imgsBoxL = document.querySelector(".mini_slide-live");
let buttonSlideL = document.querySelectorAll("#slideButton-l");
buttonSlideL.forEach((button) => {
button.addEventListener("click", () => {
const direction = button.className == "left_img_button" ? -1 : 1;
const scrollImg = direction * (imgsBoxL.clientWidth - 150);
imgsBoxL.scrollBy({ left: scrollImg, behavior: "smooth" });
});
});
let imgsBoxS;
window.addEventListener("mousedown", (e) => {
let flag =
e.target.offsetParent.className === "right_img_button" ||
e.target.offsetParent.className === "left_img_button";
imgsBoxS = e.target.offsetParent.className;
console.log(imgsBoxS);
if (flag) {
imgsBoxS = e.target.offsetParent.offsetParent.className;
console.log(imgsBoxS);
}
if (`${imgsBoxS}` == "") {
console.log("if condition block")
return;
}
let imgsBoxSItom = document.querySelector(`.${imgsBoxS}`);
let buttonSlideS = document.querySelectorAll(`.${imgsBoxS} #slideButton-s`);
console.log(imgsBoxSItom);
buttonSlideS.forEach((button) => {
button.addEventListener("click", () => {
const direction = button.className == "left_img_button" ? -1 : 1;
const scrollImg = direction * (imgs[0].clientWidth - 150);
imgsBoxSItom.scrollBy({ left: scrollImg, behavior: "smooth" });
});
});
});