-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
51 lines (46 loc) · 1.53 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
let initKey = 0;
const imgCarrousel = document.querySelector('.images');
const carouselContainer = document.querySelector('.img-carrousel');
for (let i of imgCarrousel.children) {
i.addEventListener('click', () => {
for (let j of imgCarrousel.children) {
j.style.height = '200px';
j.style.width = '200px';
}
i.style.height = '250px';
i.style.width = '250px';
initKey = i.dataset.key - 1;
});
}
const leftClick = document.querySelector('.fa-caret-left');
const rightClick = document.querySelector('.fa-caret-right');
leftClick.addEventListener('click', moveLeft);
rightClick.addEventListener('click', moveRight);
function moveLeft() {
if (initKey <= 0) {
return;
}
imgCarrousel.children[initKey].style.height = '200px';
imgCarrousel.children[initKey].style.width = '200px';
initKey--;
imgCarrousel.children[initKey].style.height = '250px';
imgCarrousel.children[initKey].style.width = '250px';
imgCarrousel.scrollLeft -= 100; // Scroll left by 250 pixels
}
function moveRight() {
if (initKey >= 6) {
return;
}
imgCarrousel.children[initKey].style.height = '200px';
imgCarrousel.children[initKey].style.width = '200px';
initKey++;
imgCarrousel.children[initKey].style.height = '250px';
imgCarrousel.children[initKey].style.width = '250px';
imgCarrousel.scrollLeft += 100; // Scroll right by 250 pixels
}
window.onload = function () {
setTimeout(() => {
imgCarrousel.children[initKey].style.height = '250px';
imgCarrousel.children[initKey].style.width = '250px';
}, 0);
};