forked from neelmani0/internal-mark-2946
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cases&Sleeves.js
76 lines (71 loc) · 2.64 KB
/
Cases&Sleeves.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
let container = document.getElementById("category-container");
// fetch("https://dbioz2ek0e.execute-api.ap-south-1.amazonaws.com/mockapi/get-tech-products")
// .then((res)=>{
// return res.json();
// })
// .then((res)=>{
// console.log(res)
// display(res.data)
// })
let data = [
{
img: "https://images.dailyobjects.com/marche/tmp/phone-cases.png?tr=cm-pad_resize,v-2,w-160,h-160,dpr-1",
category: "PHONE CASES"
},
{
img: "https://images.dailyobjects.com/marche/icons/category/cases-sleeves-intermediate-image.jpg?tr=cm-pad_crop,v-2,w-160,h-160,dpr-1",
category: "LAPTOP MACBOOK SLEEVES"
},
{
img: "https://images.dailyobjects.com/marche/icons/category/airpod-case-cover-updated.jpg?tr=cm-pad_crop,v-2,w-160,h-160,dpr-1",
category: "AIRPODS CASE COVER"
},
{
img: "https://images.dailyobjects.com/marche/icons/category/ipad-new.png?tr=cm-pad_resize,v-2,w-160,h-160,dpr-1",
category: "IPAD COVERS & SLEEVES New"
},
{
img: "https://images.dailyobjects.com/marche/icons/category/passport.png?tr=cm-pad_resize,v-2,w-160,h-160,dpr-1",
category: "PASSPORT WALLETS"
},
{
img: "https://images.dailyobjects.com/marche/icons/category/eyewear-cases.png?tr=cm-pad_resize,v-2,w-160,h-160,dpr-1",
category: "EYEWEAR CASES"
},
{
img: "https://images.dailyobjects.com/marche/icons/category/airtag-category-icon.png?tr=cm-pad_resize,v-2,w-160,h-160,dpr-1",
category: "AIRTAG CASES"
}
]
let arr = JSON.parse(localStorage.getItem("products"))||[]
display(data)
function display(data) {
container.innerHTML = "";
data.forEach((element) => {
let card = document.createElement("div");
card.setAttribute = ("class", "card")
let img = document.createElement("img");
let h3 = document.createElement("h3");
img.src = element.img;
h3.textContent = element.category;
container.append(card);
card.append(img, h3)
card.addEventListener("click", () => {
arr.shift()
arr.push(element.category)
localStorage.setItem("products",JSON.stringify(arr))
localStorage.removeItem("storedata")
window.location.href = "./Cases&Sleevespproducts.html"
})
});
}
let logo = document.getElementById("logo")
logo.addEventListener("click", () => {
window.location.href = "./index.html"
})
let cartcount = document.querySelector(".cartcount");
let cartdata = JSON.parse(localStorage.getItem("cartdata")) || [];
if (cartdata.length === 0) {
cartcount.style.display = "none"
}
cartcount.innerText = cartdata.length;