Enhance shopping cart and item detail features with new layout and styling

This commit is contained in:
vista-man
2025-02-12 13:33:49 +01:00
parent 164142806c
commit 9752c92d1c
3 changed files with 213 additions and 98 deletions

View File

@@ -17,28 +17,38 @@
<div class="menu-item" onclick="showItemDetails('Snacks')">Snacks</div> <div class="menu-item" onclick="showItemDetails('Snacks')">Snacks</div>
<div class="menu-item" onclick="showItemDetails('deserts')">Ijsjes</div> <div class="menu-item" onclick="showItemDetails('deserts')">Ijsjes</div>
<div class="menu-item" onclick="showItemDetails('Deals')">Deals</div> <div class="menu-item" onclick="showItemDetails('Deals')">Deals</div>
<div class="menu-item" onclick="showItemDetails('soepen')">Soepen</div> <div class="menu-item" onclick="showItemDetails('Soepen')">Soepen</div>
</div> <div class="menu-item" onclick="showItemDetails('Salades')">Salades</div>
<!-- placeholder-->
<!-- Rechterkant: Productafbeeldingen in mooie hokjes --> <div class="menu-item" onclick="showItemDetails('Placeholder2')">Placeholder 2</div>
<div id="product-display" class="product-display">
<!-- Hier komen de items die worden weergegeven als afbeeldingen -->
</div> </div>
<!-- Modaal venster voor grotere afbeelding en beschrijving --> <!-- Modaal venster voor grotere afbeelding en beschrijving -->
<div id="modal" class="modal" onclick="closeModal()"> <div id="modal" class="modal">
<div class="modal-content"> <div class="modal-content">
<span class="close" onclick="closeModal()">&times;</span> <span class="close" onclick="closeModal()">&times;</span>
<h2 id="modal-title"></h2> <h2 id="modal-title"></h2>
<img id="modal-image" src="" alt=""> <img id="modal-image" src="" alt="">
<p id="modal-description"></p> <p id="modal-description"></p>
<p id="modal-price"></p>
<button id="add-to-cart">Toevoegen aan winkelmandje</button>
</div> </div>
</div> </div>
<!-- Winkelmandje sectie -->
<div id="cart" class="cart">
<h2>Winkelmandje</h2>
<ul id="cart-items">
<!-- Winkelmandje items worden hier dynamisch toegevoegd -->
</ul>
<p>Totaal: €<span id="total-price">0.00</span></p>
<button id="order-button">Bestellen</button>
</div>
<footer> <footer>
<p>&copy; 2025 McDonald's</p> <p>&copy; 2025 vista </p>
</footer> </footer>
<script src="script.js"></script>
</body> </body>
<script src="script.js"></script>
</html> </html>

View File

@@ -1,91 +1,120 @@
// Array to hold items added to the shopping cart
const cart = [];
// Functie om de details van een geselecteerd item weer te geven // Functie om de details van een geselecteerd item weer te geven
function showItemDetails(item) { function showItemDetails(item) {
var items = []; var title = "";
var imageSrc = "";
var description = "";
var price = 0;
// Afhankelijk van het geselecteerde item, pas de details aan
// Afhankelijk van het geselecteerde item, voeg de producten toe
if (item === 'Broodjes') { if (item === 'Broodjes') {
items = [ title = "Broodje Gezond";
{ imageSrc = "media/broodje-gezond.jpg";
title: "Broodje Gezond", description = "Op dit broodje zit kaas, veldsla, komkommer, tomaat, ei, ham en/of kip en bufkes saus.";
image: "https://thumbs.dreamstime.com/b/submarine-sandwich-ham-cheese-clipping-path-egg-tomato-cucumber-lettuce-white-48580716.jpg", price = 3.50;
description: "Op dit broodje zit kaas, veldsla, komkommer, tomaat, ei, ham en/of kip en bufkes saus."
}
];
} else if (item === 'drinks') { } else if (item === 'drinks') {
items = [ title = "Spa Water";
{ imageSrc = "media/spa.jpg";
title: "Spa Water", description = "Koude verfrissende water.";
image: "https://m.media-amazon.com/images/I/71VrczELeaL._AC_SY741_.jpg", price = 1.00;
description: "Koude verfrissende water."
}
];
} else if (item === 'Snacks') { } else if (item === 'Snacks') {
items = [ title = "Frikandel";
{ imageSrc = "media/frikandel.jpg";
title: "Frikandel", description = "Een frikandel, dat wil je wel!";
image: "https://boshuis.huisjebezorgd.nl/wp-content/uploads/2020/03/29512948_652505005141152_1601506864166600704_o.jpg", price = 2.00;
description: "Een frikandel, dat wil je wel!"
}
];
} else if (item === 'deserts') { } else if (item === 'deserts') {
items = [ title = "Ijsjes";
{ imageSrc = "media/ijs.png";
title: "Ijsjes", description = "Een lekker ijsje met vele smaken, zoals aardbei, vanille, chocolade, mint, bosbes en nog veel meer (alleen in de zomer!).";
image: "https://th.bing.com/th/id/R.5e81f369a0da6a92106391e7b0a5119b?rik=KD0kNGiRjGM22g&riu=http%3a%2f%2fwww.brookersicecream.com%2fwp-content%2fuploads%2f2018%2f09%2fIce-Cream-Fan.png&ehk=%2bfZOURa%2fKgmE4uuuESx9We3OBrwXpPaaMZpJaBJt4bo%3d&risl=&pid=ImgRaw&r=0", price = 1.50;
description: "Een lekker ijsje met vele smaken, zoals aardbei, vanille, chocolade, mint, bosbes en nog veel meer (alleen in de zomer!)." } else if (item === 'Deals') {
} title = "Deals";
]; imageSrc = "media/deals.jpg";
description = "Onze beste deals met de beste prijzen!";
price = 10.00;
} else if (item === 'Soepen') {
title = "Soepen";
imageSrc = "media/soep.jpg";
description = "Soep van de dag! (Allergieën? Meld het bij ons!)";
price = 2.50;
} else if (item === 'Salades') {
title = "Salades";
imageSrc = "media/salade.jpg";
description = "Een heerlijke salade met verse groenten en een dressing naar keuze.";
price = 3.00;
} else if (item === 'Placeholder2') {
title = "Placeholder 2";
imageSrc = "";
description = "Beschrijving voor Placeholder 2.";
price = 0;
} }
else if (item === 'Deals') { // Update de inhoud van het modaal venster
items = [ document.getElementById("modal-title").innerText = title;
{ document.getElementById("modal-image").src = imageSrc;
title: "deals", document.getElementById("modal-description").innerText = description;
image: "", document.getElementById("modal-price").innerText = `Prijs: €${price.toFixed(2)}`;
description: "Onze beste deals met de beste prijzen!." document.getElementById("add-to-cart").onclick = function() {
} addToCart({ title, price });
]; };
}
else if (item === 'soepen') { // Zet het modaal venster zichtbaar
items = [ document.getElementById("modal").style.display = "block";
{
title: "soepen",
image: "",
description: "Soep van de dag! (Allergieën? Meld het bij ons!)."
}
];
}
// Leeg de productweergave
const productDisplay = document.getElementById('product-display');
productDisplay.innerHTML = '';
// Voeg de items toe aan de weergave
items.forEach(item => {
const productBox = document.createElement('div');
productBox.classList.add('product-box');
productBox.innerHTML = `
<img src="${item.image}" alt="${item.title}" onclick="openModal('${item.title}', '${item.image}', '${item.description}')">
<h3>${item.title}</h3>
`;
productDisplay.appendChild(productBox);
});
} }
// Functie om het modaal venster te openen // Functie om een item aan het winkelwagentje toe te voegen
function openModal(title, image, description) { function addToCart(item) {
document.getElementById("modal-title").innerText = title; cart.unshift(item); // Add item to the beginning of the cart array
document.getElementById("modal-image").src = image; updateCart();
document.getElementById("modal-description").innerText = description; closeModal();
}
// Zet het modaal venster zichtbaar // Functie om het winkelwagentje bij te werken
document.getElementById("modal").style.display = "block"; function updateCart() {
const cartItemsContainer = document.getElementById("cart-items");
cartItemsContainer.innerHTML = '';
let totalPrice = 0;
cart.forEach((item, index) => {
const cartItemElement = document.createElement('li');
cartItemElement.className = 'cart-item';
cartItemElement.innerHTML = `
<span>${item.title}</span>
<span>€${item.price.toFixed(2)}</span>
<button onclick="removeFromCart(${index})">Verwijderen</button>
`;
cartItemsContainer.appendChild(cartItemElement);
totalPrice += item.price;
});
document.getElementById('total-price').innerText = totalPrice.toFixed(2);
// Show or hide the "Bestellen" button based on the cart's content
const orderButton = document.getElementById('order-button');
if (cart.length > 0) {
orderButton.style.display = 'block';
} else {
orderButton.style.display = 'none';
}
}
// Functie om een item uit het winkelwagentje te verwijderen
function removeFromCart(index) {
cart.splice(index, 1);
updateCart();
} }
// Functie om het modaal venster te sluiten // Functie om het modaal venster te sluiten
function closeModal() { function closeModal() {
document.getElementById("modal").style.display = "none"; document.getElementById("modal").style.display = "none";
} }
// Zorg ervoor dat het modaal venster sluit wanneer er buiten het venster wordt geklikt
window.onclick = function(event) {
if (event.target == document.getElementById("modal")) {
closeModal();
}
}
// Initial call to updateCart to ensure the button is hidden on page load
updateCart();

View File

@@ -3,6 +3,8 @@ body {
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
margin: 0; margin: 0;
display: flex; display: flex;
justify-content: space-between; /* Ensure the body content is spaced between */
background-color: #f2c14e; /* Set the background color to yellow */
} }
/* Linkerkant menu */ /* Linkerkant menu */
@@ -12,6 +14,7 @@ body {
padding: 20px; padding: 20px;
height: 100vh; height: 100vh;
overflow-y: auto; overflow-y: auto;
order: 1; /* Ensure the menu is on the left */
} }
.menu-list h2 { .menu-list h2 {
@@ -22,11 +25,11 @@ body {
.menu-item { .menu-item {
background-color: #fff; background-color: #fff;
padding: 15px; padding: 20px; /* Increase padding for larger buttons */
margin: 10px 0; margin: 10px 0;
border-radius: 8px; border-radius: 8px;
cursor: pointer; cursor: pointer;
font-size: 1.2em; font-size: 1.5em; /* Increase font size for larger buttons */
transition: all 0.3s ease; transition: all 0.3s ease;
} }
@@ -53,22 +56,76 @@ body {
cursor: pointer; cursor: pointer;
} }
.product-box img { .menu-detail img {
width: 100%; width: 70%;
height: auto; max-width: 300px;
transition: transform 0.3s ease; max-height: 400px;
margin-bottom: 20px;
} }
.product-box:hover img { .menu-detail h2 {
transform: scale(1.1);
}
.product-box h3 {
font-size: 1.1em;
color: #d32f2f; color: #d32f2f;
margin: 10px 0; margin: 10px 0;
} }
.menu-item:hover {
background-color: #f59e42;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
/* Winkelmandje sectie */
.cart {
width: 30%;
background-color: #fff; /* Change background color to white */
padding: 20px;
height: 100vh;
overflow-y: auto;
order: 3; /* Ensure the cart is on the right */
position: fixed; /* Fix the cart to the right side */
right: 0; /* Align the cart to the right */
top: 0; /* Align the cart to the top */
display: flex;
flex-direction: column; /* Ensure the content is arranged in a column */
}
.cart-item {
display: flex;
justify-content: space-between;
padding: 10px 0;
border-bottom: 1px solid #ddd;
}
.cart-item button {
background-color: #d32f2f;
color: white;
border: none;
padding: 5px 10px;
cursor: pointer;
border-radius: 5px;
}
.cart-item button:hover {
background-color: #b71c1c;
}
#order-button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
width: 100%;
text-align: center;
margin-top: 20px;
display: none; /* Hide the button by default */
align-self: flex-end; /* Ensure the button is at the bottom */
}
#order-button:hover {
background-color: #45a049;
}
/* Modaal venster (pop-up) */ /* Modaal venster (pop-up) */
.modal { .modal {
display: none; display: none;
@@ -79,20 +136,25 @@ body {
width: 100%; width: 100%;
height: 100%; height: 100%;
background-color: rgba(0, 0, 0, 0.5); background-color: rgba(0, 0, 0, 0.5);
overflow: auto; /* Allow scrolling within the modal */
} }
.modal-content { .modal-content {
background-color: white; background-color: white;
margin: 15% auto; margin: 5% auto; /* Reduce margin to fit more content */
padding: 20px; padding: 20px;
border-radius: 8px; border-radius: 8px;
width: 60%; width: 80%; /* Increase width to fit more content */
max-width: 600px; /* Set a maximum width */
text-align: center; text-align: center;
max-height: 90vh; /* Ensure the modal content fits within the viewport height */
overflow-y: auto; /* Allow vertical scrolling within the modal */
} }
.modal img { .modal img {
width: 100%; width: 100%;
max-width: 200px; max-width: 300px; /* Ensure the image fits within the modal */
height: auto; /* Maintain aspect ratio */
margin: 20px 0; margin: 20px 0;
} }
@@ -105,6 +167,20 @@ body {
cursor: pointer; cursor: pointer;
} }
#add-to-cart {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
margin-top: 20px;
}
#add-to-cart:hover {
background-color: #45a049;
}
/* Footer */ /* Footer */
footer { footer {
text-align: center; text-align: center;