-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
107 lines (87 loc) · 2.59 KB
/
script.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
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
window.addEventListener("DOMContentLoaded", () => {
gsap.from("h1", {
duration: 1,
opacity: 0,
y: -50,
stagger: 0.3,
});
gsap.from(".image-container img", {
duration: 1,
opacity: 0,
scale: 0.5,
stagger: 0.2,
});
});
window.addEventListener("DOMContentLoaded", () => {
gsap.from(".imgbackground img", {
duration: 1,
opacity: 0,
y: 0,
});
gsap.from(".rectangle1", {
duration: 1,
opacity: 0,
y: 10,
});
gsap.from(".rectangle1 li", {
duration: 1,
opacity: 0,
y: 10,
stagger: 0.3,
});
});
let cartItems = [];
function incrementItem(itemName, quantityId, price) {
const quantityElement = document.getElementById(quantityId);
const quantity = parseInt(quantityElement.textContent) + 1;
quantityElement.textContent = quantity;
updateCart(itemName, quantity, price);
}
function decrementItem(itemName, quantityId, price) {
const quantityElement = document.getElementById(quantityId);
const quantity = parseInt(quantityElement.textContent);
if (quantity > 0) {
quantityElement.textContent = quantity - 1;
updateCart(itemName, quantity - 1, price);
}
}
function updateCart(itemName, quantity, price) {
const existingItemIndex = cartItems.findIndex(
(item) => item.name === itemName
);
if (existingItemIndex !== -1) {
cartItems[existingItemIndex].quantity = quantity;
} else {
cartItems.push({ name: itemName, quantity, price });
}
// Update the cart in localStorage
localStorage.setItem("cart", JSON.stringify(cartItems));
}
function viewCart() {
// Redirect to the cart page
window.location.href = "cart.html";
}
function orderNow() {
// Implement your order submission logic here
alert("Order placed successfully!");
}
document.addEventListener("DOMContentLoaded", function () {
displayCart();
});
function displayCart() {
const cartList = document.getElementById("cart-list");
const subtotalElement = document.getElementById("subtotal");
const storedCart = localStorage.getItem("cart");
const cartItems = storedCart ? JSON.parse(storedCart) : [];
let total = 0;
cartList.innerHTML = ""; // Clear the previous content
cartItems.forEach((item) => {
const listItem = document.createElement("li");
listItem.textContent = `${item.name} - Quantity: ${
item.quantity
} - Price: Rs${item.price * item.quantity}`;
cartList.appendChild(listItem);
total += item.price * item.quantity;
});
subtotalElement.textContent = `Rs${total.toFixed(2)}`;
}