-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
57 lines (47 loc) · 1.85 KB
/
Copy pathscript.js
File metadata and controls
57 lines (47 loc) · 1.85 KB
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
// HELPER FUNCTION TO INIT SLIDER
function initSlider(containerSelector, leftBtn, rightBtn, jsonFile) {
fetch(jsonFile)
.then(res => res.json())
.then(data => {
const container = document.querySelector(containerSelector);
// Inject images
data.forEach(item => {
const img = document.createElement("img");
img.src = item.image[0];
img.alt = item.name;
container.appendChild(img);
});
// Slideshow functionality
let index = 0;
const slides = container.querySelectorAll("img");
const updateSlide = () => {
container.style.transform = `translateX(-${index * 100}%)`;
};
leftBtn.addEventListener("click", () => {
index = (index - 1 + slides.length) % slides.length;
updateSlide();
});
rightBtn.addEventListener("click", () => {
index = (index + 1) % slides.length;
updateSlide();
});
});
}
// INIT ALL SLIDERS
const sliderBlocks = document.querySelectorAll(".slider-block");
sliderBlocks.forEach((block, i) => {
const leftBtn = block.querySelector(".left-btn");
const rightBtn = block.querySelector(".right-btn");
const container = block.querySelector(".slideshow-wrapper > div");
let jsonFile = "";
if (container.classList.contains("costumizetops")) jsonFile = "tops.json";
else if (container.classList.contains("costumizebottoms")) jsonFile = "bottoms.json";
else if (container.classList.contains("costumizeshoes")) jsonFile = "shoes.json";
initSlider(`.${container.className}`, leftBtn, rightBtn, jsonFile);
});
// HAMBURGER MENU
const hamburger = document.getElementById('hamburger');
const navLinks = document.querySelector('.nav');
hamburger.addEventListener('click', () => {
navLinks.classList.toggle('show');
});