ProbelaufZoo/Javascript/app.js

45 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2024-04-17 10:06:18 +02:00
const swiper = new Swiper('.swiper', {
direction: 'vertical',
loop: true,
pagination: {
el: '.swiper-pagination',
},
});
2024-04-17 23:14:22 +02:00
// Für die Links in der Navbar, dass die Striche beim aktuell geklickten bleiben
2024-04-18 16:54:15 +02:00
var navLinks = document.querySelectorAll('.navbar .nav-link');
var initialSelected = document.querySelector('.navbar .nav-link[aria-current="page"]');
if (initialSelected) {
initialSelected.classList.add('selected');
}
2024-04-17 23:14:22 +02:00
2024-04-18 16:54:15 +02:00
navLinks.forEach(function(link) {
link.addEventListener('click', function() {
// Alle anderen Links zurücksetzen
navLinks.forEach(l => l.classList.remove('selected'));
// Die 'selected' Klasse zum angeklickten Link hinzufügen
link.classList.add('selected');
});
2024-04-18 15:51:37 +02:00
});
2024-04-18 16:47:42 +02:00
2024-04-18 16:36:22 +02:00
// Für Preis
2024-04-18 16:54:15 +02:00
updatePrice();
2024-04-18 16:36:22 +02:00
function updatePrice() {
const fresserchenSelect = document.getElementById('Fresserchen');
const mengeSelect = document.getElementById('Menge');
const priceInput = document.getElementById('Preis');
const selectedFood = fresserchenSelect.options[fresserchenSelect.selectedIndex];
const pricePerUnit = selectedFood.getAttribute('data-price');
const quantity = mengeSelect.value;
const total = pricePerUnit * quantity;
2024-04-18 16:47:42 +02:00
priceInput.value = total.toFixed(2);
2024-04-18 16:36:22 +02:00
}
function showDonationAmount() {
const priceInput = document.getElementById('Preis').value;
alert('Danke für deine Spende von €' + priceInput + '!');
2024-04-18 16:54:15 +02:00
window.location.reload();
2024-04-18 16:36:22 +02:00
}