-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart5.html
346 lines (343 loc) · 8.84 KB
/
cart5.html
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<!DOCTYPE html>
<html>
<head>
<script src="https://kit.fontawesome.com/92d70a2fd8.js" crossorigin="anonymous"></script>
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'poppins', sans-serif;
font-size: 18px;
}
body{
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.header{
height: 80px;
width: 70%;
background-color: rgb(218, 106, 32);
border-radius: 3px;
margin: 30px 0px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 15px;
}
.header .logo{
font-size: 30px;
font-weight: bold;
color: white;
}
.cart{
display: flex;
background-color: white;
justify-content: space-between;
align-items: center;
padding: 7px 10px;
border-radius: 3px;
width: 80px;
}
.fa-solid{
color: rgb(218, 32, 147);
}
.cart p{
height: 22px;
width: 22px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 22px;
background-color: rgb(196, 157, 153);
color: white;
}
.container{
display: flex;
width: 70%;
margin-bottom: 30px;
}
#root{
width: 60%;
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-gap: 20px;
}
.sidebar{
width: 40%;
border-radius: 5px;
background-color: #eee;
margin-left: 20px;
padding: 15px;
text-align: center;
}
.head{
background-color: rgb(151, 145, 208);
border-radius: 3px;
height: 40px;
padding: 10px;
margin-bottom: 20px;
color: white;
display: flex;
align-items: center;
}
.foot{
display: flex;
justify-content: space-between;
margin: 20px 0px;
padding: 10px 0px;
border-top: 1px solid #333;
}
.box{
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
border: 1px solid rgb(210, 164, 99);
border-radius: 5px;
padding: 15px;
}
.img-box{
width: 100%;
height: 180px;
display: flex;
align-items: center;
justify-content: center;
}
.images{
max-width: 90%;
max-height: 90%;
object-fit: cover;
object-position: center;
}
.bottom{
margin-top: 20px;
width: 100%;
text-align: center;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
height: 110px;
}
h2{
font-size: 20px;
color: rgb(255, 0, 0);
}
button{
width: 100%;
position: relative;
border: none;
border-radius: 5px;
background-color: rgb(117, 188, 188);
padding: 7px 25px;
cursor: pointer;
color: white;
}
button:hover{
background-color: #333;
}
.cart-item{
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px;
background-color: white;
border-bottom: 1px solid #aaa;
border-radius: 3px;
margin: 10px 10px;
}
.row-img{
width: 50px;
height: 50px;
border-radius: 50px;
border: 1px solid rgb(195, 168, 100);
display: flex;
align-items: center;
justify-content: center;
}
.rowimg{
max-width: 43px;
max-height: 43px;
border-radius: 50%;
}
.fa-trash:hover{
cursor: pointer;
color: #333;
}
.placeoder{
height: 22px;
width: 22px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 22px;
background-color: goldenrod;
color: white;
}
</style>
<style>
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@700;800&family=Prompt:wght@600&display=swap');
</style>
</head>
<body>
<div class="header">
<p class="logo">HSRJY005</p>
<div class="cart"><i class="fa-solid fa-cart-shopping"></i><p id="count">0</p></div>
</div>
<div class="container">
<div id="root"></div>
<div class="sidebar">
<div class="head"><p>My Cart</p></div>
<div id="cartItem">Your cart is empty</div>
<div class="foot">
<h3>Total</h3>
<h2 id="total">$ 0.00</h2>
<div id="placeorder"><input type="button" onclick="placeorder()" value="place order" />
</div>
</div>
</div>
</div>
<script>
const product = [
{
id: 0,
image: 'https://www.vegrecipesofindia.com/wp-content/uploads/2020/12/burger-recipe-4.jpg',
title: 'Veggie Burger',
price: 120,
},
{
id: 1,
image: 'https://www.allrecipes.com/thmb/1ul-jdOz8H4b6BDrRcYOuNmJgt4=/1500x0/filters:no_upscale():max_bytes(150000):strip_icc()/239867chef-johns-chicken-tikka-masala-ddmfs-3X4-0572-e02a25f8c7b745459a9106e9eb13de10.jpg',
title: 'Chicken Tikka Masala',
price: 240,
},
{
id: 2,
image: 'https://www.indianveggiedelight.com/wp-content/uploads/2020/04/veg-biryani-instant-pot.jpg',
title: 'Vegetable Biryani ',
price: 180,
},
{
id: 3,
image: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRkwK05cpvE9hVnUGnAi84mykjffNg00W58rg&usqp=CAU',
title: 'Saag Paneer',
price: 320,
},
{
id: 4,
image: 'https://media.istockphoto.com/id/183564340/photo/close-up-photograph-of-a-pile-of-plain-naan-flatbreads.jpg?s=612x612&w=0&k=20&c=mlcv58NxCe8svyVDg27zME9FZbTx9FaUGG0utxWGZVk=',
title: 'Naan Bread',
price: 180,
},
{
id: 5,
image: 'https://t3.ftcdn.net/jpg/00/46/29/14/360_F_46291453_CJqHnfrjtb6fxsndJNB62Z4jxA7TP36R.jpg',
title: 'Butter Chicken',
price: 180,
},
{
id: 6,
image: 'https://media.istockphoto.com/id/1091565958/photo/spicy-potato-curry-indian-recipe.jpg?s=612x612&w=0&k=20&c=km419oVyfT731IrxaqSqUYGS5vgN1K1f1Xb32sw1Jms=',
title: 'Aloo Gobi',
price: 180,
},
{
id: 7,
image: 'https://img.taste.com.au/TFQ_zAsZ/taste/2017/06/lamb-rogan-josh-127388-1.jpg',
title: 'Rogan Josh (Lamb Curry)',
price: 580,
},
{
id: 8,
image: 'https://t4.ftcdn.net/jpg/02/97/69/65/360_F_297696576_s8k3pGepliFhN2oILIzLUAkQuukKalDI.jpg',
title: 'Chana Masala',
price: 179,
},
{
id: 9,
image: 'https://jyokitchen607760324.files.wordpress.com/2018/09/9ee7e-img_2805.jpg?w=1200',
title: 'Lamb Kebabs',
price: 680,
},
{
id: 10,
image: 'https://assets.epicurious.com/photos/5c745a108918ee7ab68daf79/1:1/w_2560%2Cc_limit/Smashburger-recipe-120219.jpg',
title: 'Classic Cheeseburger',
price: 99,
},
{
id: 11,
image: 'https://www.tastesoflizzyt.com/wp-content/uploads/2019/06/bacon-cheeseburger-4-500x375.jpg',
title: 'BBQ Bacon Burger',
price: 192,
},
{
id: 12,
image: 'https://www.thespruceeats.com/thmb/ri8ba_zHckEKdjPRhc1neyZsufE=/1500x0/filters:no_upscale():max_bytes(150000):strip_icc()/easy-homemade-truffle-fries-recipe-1375725-hero-02-a9d4ccb2e72544469c044f6ddd728bf3.jpg',
title: 'Truffle Fries',
price: 159,
},
];
const categories = [...new Set(product.map((item)=>
{return item}))]
let i=0;
document.getElementById('root').innerHTML = categories.map((item)=>
{
var {image, title, price} = item;
return(
`<div class='box'>
<div class='img-box'>
<img class='images' src=${image}></img>
</div>
<div class='bottom'>
<p>${title}</p>
<h2>₹ ${price}.00</h2>`+
"<button onclick='addtocart("+(i++)+")'>Add to cart</button>"+
`</div>
</div>`
)
}).join('')
var cart =[];
function addtocart(a){
cart.push({...categories[a]});
displaycart();
}
function delElement(a){
cart.splice(a, 1);
displaycart();
}
function displaycart(){
let j = 0, total=0;
document.getElementById("count").innerHTML=cart.length;
if(cart.length==0){
document.getElementById('cartItem').innerHTML = "Your cart is empty";
document.getElementById("total").innerHTML = "₹ "+0+".00";
}
else{
document.getElementById("cartItem").innerHTML = cart.map((items)=>
{
var {image, title, price} = items;
total=total+price;
document.getElementById("total").innerHTML = "₹ "+total+".00";
return(
`<div class='cart-item'>
<div class='row-img'>
<img class='rowimg' src=${image}>
</div>
<p style='font-size:12px;'>${title}</p>
<h2 style='font-size: 15px;'>₹ ${price}.00</h2>`+
"<i class='fa-solid fa-trash' onclick='delElement("+ (j++) +")'></i></div>"
);
}).join('');
}
}
function placeorder() {
alert("Details to fill")
window.location.assign('order.html');
}
</script>
</body>
</html>