-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.js
81 lines (71 loc) · 2.44 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
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
let Category=document.getElementById("category");
function dispro(data){
data.forEach((obj) =>{
let div= document.createElement("div");
let imgDiv=document.createElement("div");
let imgTag=document.createElement("img");
imgTag.src=obj.image;
imgDiv.append(imgTag);
let aTag=document.createElement("a");
aTag.innerText=obj.text;
let aDiv=document.createElement("p");
aDiv.append(aTag);
div.append(imgDiv,aDiv);
Category.append(div);
})
}
//for gallery slider
let cont=document.querySelector(".gallery");
let cont1=document.querySelector(".gallery1");
let nextbtn=document.getElementById("next-btn");
let backbtn=document.getElementById("back-btn");
let nextbtn1=document.getElementById("nextbtn");
let backbtn1=document.getElementById("backbtn");
nextbtn.addEventListener("click",() => {
cont.style.scrollBehavior="smooth";
cont.scrollLeft+=380;
})
backbtn.addEventListener("click",() => {
cont.style.scrollBehavior="smooth";
cont.scrollLeft-=380;
})
nextbtn1.addEventListener("click",() => {
cont1.style.scrollBehavior="smooth";
cont1.scrollLeft+=380;
})
backbtn1.addEventListener("click",() => {
cont1.style.scrollBehavior="smooth";
cont1.scrollLeft-=380;
})
//Add to cart function
let AtoC=document.querySelectorAll(".AtoC");
AtoC.forEach((el)=>{
el.addEventListener("click",()=>{
let proData=document.querySelector(".part");
let cartData=document.getElementById("cart-item");
console.log("ayush")
cartData.push(proData)
})
})
//search feature
let search=()=>{
let searchbox=document.getElementById("search-bar").value.toUpperCase();
let product_category=document.getElementById("gallery");
let product=document.querySelectorAll(".gallery-div");
let pname=product_category.querySelectorAll("a");
for(let i=0;i<pname.length;i++){
let match=product[i].querySelectorAll("a")[0];
if(match){
let textvalue= match.innerHTML || match.innerText || match.textContent
if(textvalue.toUpperCase().indexOf(searchbox) > -1){
product[i].style.display="";
}else{
product[i].style.display="none";
}
}
}
}
fetch("./home.json")
.then((res)=>res.json())
.then((data)=> dispro(data))
.catch((err)=> console.log(err));