-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
107 lines (55 loc) · 1.81 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
104
105
console.log("Hello World");
const forLoaderBody=document.body.querySelector(".forLoaderBody");
const containerLoader=document.body.querySelector(".containerLoader");
window.addEventListener("load",(e)=>{
setTimeout(()=>{
containerLoader.style.display="none";
forLoaderBody.classList.remove("forLoaderBody");
}, 3000); //3 second delay
})
const slider = document.querySelector(".cardClick");
const slideImg = document.querySelectorAll(".cardClick img");
const width = slideImg[0].clientWidth;
let counter = -width;
slider.addEventListener("dblclick", () => {
slideImg.forEach(img => {
img.style.transform = `translateX(${counter}px)`;
});
counter -= width;
if (counter === -4 * width) {
counter = 0;
}
});
const sliderMask = document.querySelector(".cardClickMask");
const slideMaskImg = document.querySelectorAll(".cardClickMask img");
const widthM = slideImg[0].clientWidth;
let counterM = -widthM;
sliderMask.addEventListener("click", () => {
slideMaskImg.forEach(img => {
img.style.transform = `translateX(${counter}px)`;
});
counter -= widthM;
if (counter === -4 * widthM) {
counter = 0;
}
});
const cardAutoByJS = document.querySelector(".cardAutoByJS");
const slideAutoByJS = document.querySelectorAll(".cardAutoByJS img");
let positionX = 0;
function animate() {
setTimeout(() => {
if (positionX === -4 * width) {
positionX = 0;
}
slideAutoByJS.forEach(image => {
image.style.transform = `translateX(${positionX}px)`;
});
positionX -= width;
requestAnimationFrame(animate);
}, 3000);
}
requestAnimationFrame(animate); //animate()
const allImages = document.querySelectorAll("img");
allImages.forEach(image => {
image.setAttribute("loading", "lazy");
});