Galerie Java Script mit Filter Funktion

// gallery.js

// Vorschaufunktion (Popup)
document.querySelectorAll('.gallery-item img').forEach(img => {
	img.addEventListener('click', () => {
		// Erstelle ein Modal-Element
		const modal = document.createElement('div');
		modal.classList.add('modal');

		// Füge das Bild in das Modal ein
		const modalImg = document.createElement('img');
		modalImg.src = img.src;
		modalImg.alt = img.alt;

		// Schließe das Modal, wenn darauf geklickt wird
		modal.addEventListener('click', () => {
			document.body.removeChild(modal);
		});

		// Füge das Bild in das Modal und das Modal ins Dokument
		modal.appendChild(modalImg);
		document.body.appendChild(modal);
	});
});

// Filterfunktion
const filterDropdown = document.getElementById('filter');
if (filterDropdown) {
	filterDropdown.addEventListener('change', function () {
		const category = this.value; // Aktuell ausgewählte Kategorie
		const items = document.querySelectorAll('.gallery-item');

		items.forEach(item => {
			// Zeige oder verstecke Elemente basierend auf der Kategorie
			if (category === 'all' || item.dataset.category === category) {
				item.style.display = 'block';
			} else {
				item.style.display = 'none';
			}
		});
	});
}

    
Galerie CSS und Filter Dropdown Box

/* Kachel-Design mit festem 10-Spalten-Layout */
.gallery {
    display: grid;
    grid-template-columns: repeat(10, 1fr); /* 10 Spalten */
    gap: 15px;
    margin: 20px auto 0;
    width: 70%; /* 70% der Seitenbreite */
    box-sizing: border-box;
}

.gallery-item {
    position: relative;
    overflow: hidden;
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid #1f1f1f;
    transition: border-color 0.3s;
}

.gallery-item img {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: auto;
    transform: translate(-50%, -50%);
    min-width: 100%;
    min-height: 100%;
    object-fit: cover;
    display: block;
}

.gallery-item:hover {
    border-color: #ff9800;
}

/* Modal Styling */
.modal {
    display: flex; /* Muss "flex" sein */
    justify-content: center;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 1000;
}

.modal img {
    max-width: 90%;
    max-height: 90%;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    transition: transform 0.3s ease-in-out;
}

.modal img:hover {
    transform: scale(1.05);
}

.modal:target {
    display: flex;
}

/* Filter Dropdown */
#filter {
    margin-bottom: 20px;
    padding: 10px;
    font-size: 1rem;
    border: 1px solid #ccc;
    border-radius: 5px;
    background-color: #1f1f1f;
    color: #e0e0e0;
    transition: border-color 0.3s;
}

#filter:focus {
    border-color: #ff9800;
    outline: none;
}