-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.js
47 lines (38 loc) · 1.21 KB
/
home.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
"use strict";
let firstGalleryContainer = document.querySelector(".first-gallery__items");
let leftArrow = document.getElementById("left-arrow");
let rightArrow = document.getElementById("right-arrow");
let secondGalleryItems = document.querySelectorAll(
".second-gallery__items .item"
);
let secondGalleryContainer = document.querySelector(".second-gallery__items");
let position = 0;
let width = 300;
initializeSlider();
function initializeSlider() {
slideGalleryWithClick(leftArrow);
slideGalleryWithClick(rightArrow);
}
function slideGalleryWithClick(button) {
button.addEventListener("click", (e) => {
if (button === leftArrow) {
position += width;
position = Math.min(position, 0);
} else {
position -= width;
position = Math.max(position, -width * (secondGalleryItems.length - 4));
}
secondGalleryContainer.style.marginLeft = position + "px";
});
}
chooseProduct()
function chooseProduct() {
const products = document.querySelectorAll('.item')
products.forEach(prod => {
prod.addEventListener('click', e => {
if(e.target.classList.contains('second-icon')) {
console.log(e.target);
}
})
})
}