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('deserts')">Ijsjes</div>
<div class="menu-item" onclick="showItemDetails('Deals')">Deals</div>
<div class="menu-item" onclick="showItemDetails('soepen')">Soepen</div>
</div>
<!-- Rechterkant: Productafbeeldingen in mooie hokjes -->
<div id="product-display" class="product-display">
<!-- Hier komen de items die worden weergegeven als afbeeldingen -->
<div class="menu-item" onclick="showItemDetails('Soepen')">Soepen</div>
<div class="menu-item" onclick="showItemDetails('Salades')">Salades</div>
<!-- placeholder-->
<div class="menu-item" onclick="showItemDetails('Placeholder2')">Placeholder 2</div>
</div>
<!-- Modaal venster voor grotere afbeelding en beschrijving -->
<div id="modal" class="modal" onclick="closeModal()">
<div id="modal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeModal()">&times;</span>
<h2 id="modal-title"></h2>
<img id="modal-image" src="" alt="">
<p id="modal-description"></p>
<p id="modal-price"></p>
<button id="add-to-cart">Toevoegen aan winkelmandje</button>
</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>
<p>&copy; 2025 McDonald's</p>
<p>&copy; 2025 vista </p>
</footer>
<script src="script.js"></script>
</body>
<script src="script.js"></script>
</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
function showItemDetails(item) {
var items = [];
var title = "";
var imageSrc = "";
var description = "";
var price = 0;
// Afhankelijk van het geselecteerde item, voeg de producten toe
// Afhankelijk van het geselecteerde item, pas de details aan
if (item === 'Broodjes') {
items = [
{
title: "Broodje Gezond",
image: "https://thumbs.dreamstime.com/b/submarine-sandwich-ham-cheese-clipping-path-egg-tomato-cucumber-lettuce-white-48580716.jpg",
description: "Op dit broodje zit kaas, veldsla, komkommer, tomaat, ei, ham en/of kip en bufkes saus."
}
];
title = "Broodje Gezond";
imageSrc = "media/broodje-gezond.jpg";
description = "Op dit broodje zit kaas, veldsla, komkommer, tomaat, ei, ham en/of kip en bufkes saus.";
price = 3.50;
} else if (item === 'drinks') {
items = [
{
title: "Spa Water",
image: "https://m.media-amazon.com/images/I/71VrczELeaL._AC_SY741_.jpg",
description: "Koude verfrissende water."
}
];
title = "Spa Water";
imageSrc = "media/spa.jpg";
description = "Koude verfrissende water.";
price = 1.00;
} else if (item === 'Snacks') {
items = [
{
title: "Frikandel",
image: "https://boshuis.huisjebezorgd.nl/wp-content/uploads/2020/03/29512948_652505005141152_1601506864166600704_o.jpg",
description: "Een frikandel, dat wil je wel!"
}
];
title = "Frikandel";
imageSrc = "media/frikandel.jpg";
description = "Een frikandel, dat wil je wel!";
price = 2.00;
} else if (item === 'deserts') {
items = [
{
title: "Ijsjes",
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",
description: "Een lekker ijsje met vele smaken, zoals aardbei, vanille, chocolade, mint, bosbes en nog veel meer (alleen in de zomer!)."
}
];
title = "Ijsjes";
imageSrc = "media/ijs.png";
description = "Een lekker ijsje met vele smaken, zoals aardbei, vanille, chocolade, mint, bosbes en nog veel meer (alleen in de zomer!).";
price = 1.50;
} 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') {
items = [
{
title: "deals",
image: "",
description: "Onze beste deals met de beste prijzen!."
}
];
}
// Update de inhoud van het modaal venster
document.getElementById("modal-title").innerText = title;
document.getElementById("modal-image").src = imageSrc;
document.getElementById("modal-description").innerText = description;
document.getElementById("modal-price").innerText = `Prijs: €${price.toFixed(2)}`;
document.getElementById("add-to-cart").onclick = function() {
addToCart({ title, price });
};
else if (item === 'soepen') {
items = [
{
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);
});
// Zet het modaal venster zichtbaar
document.getElementById("modal").style.display = "block";
}
// Functie om het modaal venster te openen
function openModal(title, image, description) {
document.getElementById("modal-title").innerText = title;
document.getElementById("modal-image").src = image;
document.getElementById("modal-description").innerText = description;
// Functie om een item aan het winkelwagentje toe te voegen
function addToCart(item) {
cart.unshift(item); // Add item to the beginning of the cart array
updateCart();
closeModal();
}
// Zet het modaal venster zichtbaar
document.getElementById("modal").style.display = "block";
// Functie om het winkelwagentje bij te werken
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
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;
margin: 0;
display: flex;
justify-content: space-between; /* Ensure the body content is spaced between */
background-color: #f2c14e; /* Set the background color to yellow */
}
/* Linkerkant menu */
@@ -12,6 +14,7 @@ body {
padding: 20px;
height: 100vh;
overflow-y: auto;
order: 1; /* Ensure the menu is on the left */
}
.menu-list h2 {
@@ -22,11 +25,11 @@ body {
.menu-item {
background-color: #fff;
padding: 15px;
padding: 20px; /* Increase padding for larger buttons */
margin: 10px 0;
border-radius: 8px;
cursor: pointer;
font-size: 1.2em;
font-size: 1.5em; /* Increase font size for larger buttons */
transition: all 0.3s ease;
}
@@ -53,22 +56,76 @@ body {
cursor: pointer;
}
.product-box img {
width: 100%;
height: auto;
transition: transform 0.3s ease;
.menu-detail img {
width: 70%;
max-width: 300px;
max-height: 400px;
margin-bottom: 20px;
}
.product-box:hover img {
transform: scale(1.1);
}
.product-box h3 {
font-size: 1.1em;
.menu-detail h2 {
color: #d32f2f;
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) */
.modal {
display: none;
@@ -79,20 +136,25 @@ body {
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
overflow: auto; /* Allow scrolling within the modal */
}
.modal-content {
background-color: white;
margin: 15% auto;
margin: 5% auto; /* Reduce margin to fit more content */
padding: 20px;
border-radius: 8px;
width: 60%;
width: 80%; /* Increase width to fit more content */
max-width: 600px; /* Set a maximum width */
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 {
width: 100%;
max-width: 200px;
max-width: 300px; /* Ensure the image fits within the modal */
height: auto; /* Maintain aspect ratio */
margin: 20px 0;
}
@@ -105,6 +167,20 @@ body {
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 {
text-align: center;