-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
87 lines (59 loc) · 2.28 KB
/
script.js
File metadata and controls
87 lines (59 loc) · 2.28 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
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
const toggleBtn = document.getElementById("toggleBtn");
const extraItems = document.querySelectorAll(".extra-categories");
const buttonText = document.querySelector(".more-less")
const arrowIcon = document.querySelector(".arrow-up-down")
toggleBtn.addEventListener("click", () => {
extraItems.forEach(item => {
item.classList.toggle("show");
});
arrowIcon.classList.toggle("less-arrow")
buttonText.innerText =
extraItems[0].classList.contains("show")
? "Show Less"
: "Show More";
});
// home page pe jo items hai unme add to cart karne ke liye
let secondContainer = document.querySelector(".quench")
secondContainer.addEventListener("click",(e)=>{
if(!e.target.classList.contains("cart")) return
e.preventDefault()
e.stopPropagation()
const card = e.target.closest(".pahla")
const id = card.dataset.id
const product = products.find(p=> p.id == id)
addToCart(product)
})
// niche wale products ke liye
let thirdContainer = document.querySelector(".dairy")
thirdContainer.addEventListener("click",(e)=>{
if(!e.target.classList.contains("cart")) return
e.preventDefault()
e.stopPropagation()
const card = e.target.closest(".pahla")
const id = card.dataset.id
const product = products.find(p=> p.id == id)
addToCart(product)
})
// niche wale cards scroller ka logic
const allSections = document.querySelectorAll('.product-section');
allSections.forEach((section) => {
const container = section.querySelector('.saaman');
const btnRight = section.querySelector('.right');
const btnLeft = section.querySelector('.left');
if(!container || !btnRight || !btnLeft) return;
btnRight.addEventListener('click', () => {
const maxScroll = container.scrollWidth - container.clientWidth;
if (Math.ceil(container.scrollLeft) >= maxScroll - 10) {
container.scrollTo({ left: 0, behavior: 'smooth' });
} else {
container.scrollBy({ left: container.clientWidth, behavior: 'smooth' });
}
});
btnLeft.addEventListener("click", () => {
if (container.scrollLeft <= 20) {
container.scrollTo({ left: container.scrollWidth, behavior: 'smooth' });
} else {
container.scrollBy({ left: -container.clientWidth, behavior: 'smooth' });
}
});
});