forked from Bhaskar977/wild-request-6662
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.html
105 lines (95 loc) · 2.74 KB
/
cart.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cart</title>
<style>
.cart-container {
border: 1px solid rgb(77, 76, 76);
width: 40%;
padding: 0px 20px 20px 20px;
margin-left: 20%;
margin-top: 20px;
margin-bottom: 180px;
border-radius: 20px;
}
.cart-container>div {
box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px;
margin-top: 40px;
padding: 20px;
border-radius: 10px;
display: flex;
justify-content: space-evenly;
}
.cart-container>div>div:nth-child(2) {
width: 140%;
margin-left: 80px;
}
.cart-container img {
width: 40%;
}
.cart-container>div button {
padding: 7px 12px 7px 12px;
background-color: aquamarine;
border: none;
color: #fff
}
#item {
margin-left: 20%;
margin-top: 50px;
font-size: 50px;
}
</style>
</head>
<body>
<div>
<div id="item"> <span id="s"> 0 </span>-Items in your cart </div>
<!-- <div>Total Price:- <span id="price">0</span> </div> -->
<div class="cart-container">
</div>
<!-- <div class="cart-total">Total</div> -->
</div>
</body>
</html>
<script>
let LSdata = JSON.parse(localStorage.getItem('cartdata'));
//let p = document.querySelector("#price")
let cc = document.querySelector('.cart-container');
let TotalTask = document.querySelector("#s")
function displayTrend (LSdata, i)
{
cc.innerHTML = null;
TotalTask.textContent = LSdata.length;
LSdata.forEach((el) =>
{
//console.log(el);
let div = document.createElement('div');
let div1 = document.createElement('div');
let div2 = document.createElement("div")
let image = document.createElement('img');
image.setAttribute('src', el.img);
let head = document.createElement('h3');
head.innerText = el.head;
let price = document.createElement('p');
price.innerText = el.price;
let del = document.createElement('button');
del.innerText = 'Remove Item';
del.addEventListener('click', function ()
{
LSdata.splice(i, 1);
localStorage.setItem('cartdata', JSON.stringify(LSdata));
displayTrend(LSdata);
});
div1.append(image)
div2.append(head, price, del)
div.append(div1, div2);
cc.append(div);
});
}
// let out=LSdata.reduce((acc,ele)=>acc+ele.price,0)
// document.querySelector(".cart-total").innerText=out
// console.log(out)
displayTrend(LSdata);
</script>