Skip to content

Commit 7e050f7

Browse files
authored
Merge pull request #58 from mfatima05/ecommerce
Ecommerce Website Using HTML, CSS and JS
2 parents a514f29 + 9c69633 commit 7e050f7

25 files changed

+971
-0
lines changed

Ecommerce/app.js

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
const wrapper = document.querySelector(".sliderWrapper");
2+
const menuItems = document.querySelectorAll(".menuItem");
3+
4+
const products = [
5+
{
6+
id: 1,
7+
title: "Nike",
8+
price: 119,
9+
colors: [
10+
{
11+
code: "black",
12+
img: "./img/nike.png",
13+
},
14+
{
15+
code: "darkblue",
16+
img: "./img/nike2.png",
17+
},
18+
],
19+
},
20+
{
21+
id: 2,
22+
title: "Adidas",
23+
price: 149,
24+
colors: [
25+
{
26+
code: "lightgray",
27+
img: "./img/adidas.png",
28+
},
29+
{
30+
code: "green",
31+
img: "./img/adidas2.png",
32+
},
33+
],
34+
},
35+
{
36+
id: 3,
37+
title: "Puma",
38+
price: 109,
39+
colors: [
40+
{
41+
code: "lightgray",
42+
img: "./img/puma.png",
43+
},
44+
{
45+
code: "green",
46+
img: "./img/puma2.png",
47+
},
48+
],
49+
},
50+
{
51+
id: 4,
52+
title: "Reebok",
53+
price: 129,
54+
colors: [
55+
{
56+
code: "black",
57+
img: "./img/reebok.png",
58+
},
59+
{
60+
code: "lightgray",
61+
img: "./img/reebok2.png",
62+
},
63+
],
64+
},
65+
{
66+
id: 5,
67+
title: "Sketchers",
68+
price: 99,
69+
colors: [
70+
{
71+
code: "gray",
72+
img: "./img/sketchers.png",
73+
},
74+
{
75+
code: "black",
76+
img: "./img/sketchers2.png",
77+
},
78+
],
79+
},
80+
];
81+
82+
let choosenProduct = products[0];
83+
84+
const currentProductImg = document.querySelector(".productImg");
85+
const currentProductTitle = document.querySelector(".productTitle");
86+
const currentProductPrice = document.querySelector(".productPrice");
87+
const currentProductColors = document.querySelectorAll(".color");
88+
const currentProductSizes = document.querySelectorAll(".size");
89+
90+
menuItems.forEach((item, index) => {
91+
item.addEventListener("click", () => {
92+
//change the current slide
93+
wrapper.style.transform = `translateX(${-100 * index}vw)`;
94+
95+
//change the choosen product
96+
choosenProduct = products[index];
97+
98+
//change texts of currentProduct
99+
currentProductTitle.textContent = choosenProduct.title;
100+
currentProductPrice.textContent = "$" + choosenProduct.price;
101+
currentProductImg.src = choosenProduct.colors[0].img;
102+
103+
//assing new colors
104+
currentProductColors.forEach((color, index) => {
105+
color.style.backgroundColor = choosenProduct.colors[index].code;
106+
});
107+
});
108+
});
109+
110+
currentProductColors.forEach((color, index) => {
111+
color.addEventListener("click", () => {
112+
currentProductImg.src = choosenProduct.colors[index].img;
113+
});
114+
});
115+
116+
currentProductSizes.forEach((size, index) => {
117+
size.addEventListener("click", () => {
118+
currentProductSizes.forEach((size) => {
119+
size.style.backgroundColor = "white";
120+
size.style.color = "black";
121+
});
122+
size.style.backgroundColor = "black";
123+
size.style.color = "white";
124+
});
125+
});
126+
127+
const productButton = document.querySelector(".productButton");
128+
const payment = document.querySelector(".payment");
129+
const close = document.querySelector(".close");
130+
131+
productButton.addEventListener("click", () => {
132+
payment.style.display = "flex";
133+
});
134+
135+
close.addEventListener("click", () => {
136+
payment.style.display = "none";
137+
});

Ecommerce/img/adidas.png

116 KB
Loading

Ecommerce/img/adidas2.png

409 KB
Loading

Ecommerce/img/contact.png

53.6 KB
Loading

Ecommerce/img/facebook.png

2.94 KB
Loading

Ecommerce/img/gift.png

35.2 KB
Loading

Ecommerce/img/instagram.png

9.37 KB
Loading

Ecommerce/img/master.png

23.1 KB
Loading

Ecommerce/img/nike.png

114 KB
Loading

Ecommerce/img/nike2.png

97.7 KB
Loading

0 commit comments

Comments
 (0)