Skip to content

Commit 9250970

Browse files
committed
Succesful addition of products using Json
1 parent a2d479f commit 9250970

File tree

6 files changed

+439
-29
lines changed

6 files changed

+439
-29
lines changed
File renamed without changes.
File renamed without changes.

app.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const D_image = document.querySelector(".DisplayImage")
33
const IntroText = document.querySelector(".IntroText")
44
const MenuBtn = document.querySelector("#MenuBtn")
55
const Nav = document.querySelector("nav")
6+
const CardsHolder = document.querySelector(".CardsHolder")
67
/// animations
78

89
// anime js 1. Display Image
@@ -21,7 +22,7 @@ const Nav = document.querySelector("nav")
2122
ScrollReveal().reveal('.IntroText', { delay: 500});
2223
ScrollReveal().reveal('.HomeBtns', { delay: 700});
2324
ScrollReveal().reveal('.DisplayImage', { delay: 800});
24-
ScrollReveal().reveal('.ProductCard', { delay: 1000});
25+
ScrollReveal().reveal('.ProductCard', { delay: 2000});
2526
ScrollReveal().reveal('form', { delay: 1000});
2627
ScrollReveal().reveal('.SocialLinks', { delay: 1000});
2728
ScrollReveal().reveal('.Links', { delay: 700});
@@ -68,4 +69,41 @@ window.onclick = function(e){
6869
}
6970
// give header background on scrolling
7071

71-
// window.onscroll = document.querySelector("header").classList.add("Scrolled")
72+
// window.onscroll = document.querySelector("header").classList.add("Scrolled")
73+
74+
75+
// json fetching
76+
77+
GetProducts();
78+
function GetProducts(){
79+
fetch("./products.json")
80+
.then(response => response.json())
81+
.then(data =>{
82+
console.log(data);
83+
data.map(data=>{
84+
console.log(data.name);
85+
// create card for each data
86+
CreateProductCard(data.image, data.name, data.company, data.make, data.cost)
87+
})
88+
});
89+
90+
}
91+
92+
93+
// create a product Card and appends to CardsHolder
94+
function CreateProductCard(Pimage, PName, PCompany, PMake, PCost){
95+
let newCard = document.createElement("div")
96+
newCard.classList = "ProductCard"
97+
newCard.innerHTML = `
98+
<img src="${Pimage}" alt="Loading Image">
99+
<h3 class="ProductName">${PName}</h3>
100+
<h3 class="ProductCompany">${PCompany}</h3>
101+
<h3 class="ProductMake">${PMake}</h3>
102+
<h3>Ksh. <span id="ProductCost"></span>${PCost}</h3>
103+
<button class="btn" id="CartItem">Add to Cart</button>
104+
`;
105+
106+
CardsHolder.append(newCard);
107+
}
108+
109+
// Displaying Products depending on the category the user wants

index.html

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,41 +70,17 @@ <h1>Our Products</h1>
7070

7171

7272
<div class="CardsHolder">
73-
<div class="ProductCard">
73+
<!-- <div class="ProductCard">
7474
<img src="./Images/Samsung Camera2.png" alt="Loading Image">
7575
<h3 class="ProductName">Lorem ipsum dolor sit amet.</h3>
7676
<h3 class="ProductCompany">Lorem, ipsum.</h3>
7777
<h3 class="ProductMake">2012 Brand New</h3>
7878
<h3>Ksh. <span id="ProductCost"></span>2300</h3>
7979
<button class="btn" id="CartItem">Add to Cart</button>
80-
</div>
80+
</div> -->
8181

82-
<div class="ProductCard">
83-
<img src="./Images/Samsung Camera1.png" alt="Loading Image">
84-
<h3 class="ProductName">Lorem ipsum dolor sit amet.</h3>
85-
<h3 class="ProductCompany">Lorem, ipsum.</h3>
86-
<h3 class="ProductMake">2012 Brand New</h3>
87-
<h3>Ksh. <span id="ProductCost"></span>2300</h3>
88-
<button class="btn" id="CartItem">Add to Cart</button>
89-
</div>
9082

91-
<div class="ProductCard">
92-
<img src="./Images/Printer7.png" alt="Loading Image">
93-
<h3 class="ProductName">Lorem ipsum dolor sit amet.</h3>
94-
<h3 class="ProductCompany">Lorem, ipsum.</h3>
95-
<h3 class="ProductMake">2012 Brand New</h3>
96-
<h3>Ksh. <span id="ProductCost"></span>2300</h3>
97-
<button class="btn" id="CartItem">Add to Cart</button>
98-
</div>
9983

100-
<div class="ProductCard">
101-
<img src="./Images/ComputerA1.png" alt="Loading Image">
102-
<h3 class="ProductName">Lorem ipsum dolor sit amet.</h3>
103-
<h3 class="ProductCompany">Lorem, ipsum.</h3>
104-
<h3 class="ProductMake">2012 Brand New</h3>
105-
<h3>Ksh. <span id="ProductCost"></span>2300</h3>
106-
<button class="btn" id="CartItem">Add to Cart</button>
107-
</div>
10884

10985
</div>
11086

0 commit comments

Comments
 (0)