Oto kod zaawansowanej galerii 3D z przykładowymi darmowymi zdjęciami. Wykorzystuje CSS transformacje 3D i JavaScript do interaktywnej nawigacji.
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Zaawansowana Galeria 3D</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: #111;
color: white;
overflow-x: hidden;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
perspective: 1000px;
}
.gallery-container {
width: 100%;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.gallery {
width: 80vw;
height: 80vh;
position: relative;
transform-style: preserve-3d;
transition: transform 1s ease;
}
.image-container {
position: absolute;
width: 60%;
height: 60%;
left: 20%;
top: 20%;
overflow: hidden;
border-radius: 10px;
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
transform-style: preserve-3d;
transition: transform 0.5s ease, opacity 0.5s ease;
cursor: pointer;
}
.image-container img {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.5s ease;
}
.image-container:hover img {
transform: scale(1.05);
}
.image-info {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
padding: 20px;
background: rgba(0, 0, 0, 0.7);
color: white;
transform: translateY(100%);
transition: transform 0.3s ease;
}
.image-container:hover .image-info {
transform: translateY(0);
}
.controls {
position: fixed;
bottom: 30px;
display: flex;
gap: 20px;
z-index: 100;
}
.control-btn {
background: rgba(255, 255, 255, 0.2);
border: none;
color: white;
padding: 12px 25px;
border-radius: 30px;
cursor: pointer;
font-weight: bold;
transition: background 0.3s ease, transform 0.2s ease;
backdrop-filter: blur(5px);
}
.control-btn:hover {
background: rgba(255, 255, 255, 0.3);
transform: scale(1.05);
}
.control-btn:active {
transform: scale(0.95);
}
.view-mode-toggle {
position: fixed;
top: 30px;
right: 30px;
background: rgba(255, 255, 255, 0.2);
border: none;
color: white;
padding: 10px 20px;
border-radius: 30px;
cursor: pointer;
backdrop-filter: blur(5px);
z-index: 100;
}
/* Animacje */
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
.active-image {
animation: pulse 2s infinite;
z-index: 10;
}
/* Tryb płaski */
.flat-mode .gallery {
transform: none !important;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 20px;
width: 90%;
height: auto;
padding: 50px 0;
}
.flat-mode .image-container {
position: relative;
width: 100%;
height: 300px;
left: 0;
top: 0;
transform: none !important;
}
</style>
</head>
<body>
<div class="gallery-container">
<div class="gallery" id="gallery"></div>
</div>
<div class="controls">
<button class="control-btn" id="prev">← Poprzedni</button>
<button class="control-btn" id="next">Następny →</button>
</div>
<button class="view-mode-toggle" id="viewToggle">Przełącz widok</button>
<script>
// Dane zdjęć (darmowe zdjęcia z Unsplash)
const images = [
{
url: 'https://images.unsplash.com/photo-1682687220063-4742bd7fd538',
title: 'Górski krajobraz',
description: 'Majestatyczne góry o zachodzie słońca'
},
{
url: 'https://images.unsplash.com/photo-1682687220208-22d7a2543e88',
title: 'Plaża tropikalna',
description: 'Rajska plaża z palmami i turkusową wodą'
},
{
url: 'https://images.unsplash.com/photo-1682687220923-c58b9a4592ea',
title: 'Miejskie światła',
description: 'Panorama miasta nocą z kolorowymi światłami'
},
{
url: 'https://images.unsplash.com/photo-1682687220067-dced9a881b56',
title: 'Las we mgle',
description: 'Tajemniczy las spowity poranną mgłą'
},
{
url: 'https://images.unsplash.com/photo-1682687220795-8c09f4b78d55',
title: 'Pustynia',
description: 'Bezkresne wydmy piaskowe o zachodzie słońca'
},
{
url: 'https://images.unsplash.com/photo-1682687220015-a1677b6209a3',
title: 'Wodospad',
description: 'Potężny wodospad w sercu dżungli'
},
{
url: 'https://images.unsplash.com/photo-1682687220509-61b8a906ca19',
title: 'Zorza polarna',
description: 'Spektakularna zorza polarna nad jeziorem'
},
{
url: 'https://images.unsplash.com/photo-1682687220566-5599dbbebf11',
title: 'Architektura',
description: 'Nowoczesna architektura z geometrycznymi kształtami'
}
];
// Zmienne globalne
let currentIndex = 0;
let rotationY = 0;
let isFlatMode = false;
// Inicjalizacja galerii
function initGallery() {
const gallery = document.getElementById('gallery');
gallery.innerHTML = '';
images.forEach((image, index) => {
const container = document.createElement('div');
container.className = 'image-container';
container.dataset.index = index;
const img = document.createElement('img');
img.src = `${image.url}?auto=format&fit=crop&w=1200&q=80`;
img.alt = image.title;
const info = document.createElement('div');
info.className = 'image-info';
info.innerHTML = `
<h3>${image.title}</h3>
<p>${image.description}</p>
`;
container.appendChild(img);
container.appendChild(info);
gallery.appendChild(container);
container.addEventListener('click', () => {
if (!isFlatMode) {
currentIndex = index;
updateGallery();
}
});
});
updateGallery();
}
// Aktualizacja pozycji zdjęć w galerii 3D
function updateGallery() {
const gallery = document.getElementById('gallery');
const containers = document.querySelectorAll('.image-container');
if (!isFlatMode) {
gallery.style.transform = `rotateY(${rotationY}deg)`;
containers.forEach((container, index) => {
const theta = (index - currentIndex) * (360 / images.length);
const radius = window.innerWidth < 768 ? 400 : 600;
container.style.transform = `rotateY(${theta}deg) translateZ(${radius}px)`;
// Przezroczystość w zależności od pozycji
const distance = Math.abs(((theta + 180) % 360) - 180);
const opacity = 1 - (distance / 180) * 0.8;
container.style.opacity = opacity;
// Aktywne zdjęcie
if (index === currentIndex) {
container.classList.add('active-image');
} else {
container.classList.remove('active-image');
}
});
}
}
// Obsługa przycisków nawigacji
document.getElementById('prev').addEventListener('click', () => {
if (isFlatMode) return;
currentIndex = (currentIndex - 1 + images.length) % images.length;
rotationY += 360 / images.length;
updateGallery();
});
document.getElementById('next').addEventListener('click', () => {
if (isFlatMode) return;
currentIndex = (currentIndex + 1) % images.length;
rotationY -= 360 / images.length;
updateGallery();
});
// Przełączanie trybu widoku
document.getElementById('viewToggle').addEventListener('click', () => {
isFlatMode = !isFlatMode;
document.body.classList.toggle('flat-mode', isFlatMode);
if (isFlatMode) {
document.getElementById('viewToggle').textContent = 'Widok 3D';
} else {
document.getElementById('viewToggle').textContent = 'Widok płaski';
updateGallery();
}
});
// Obsługa klawiszy strzałek
document.addEventListener('keydown', (e) => {
if (isFlatMode) return;
if (e.key === 'ArrowLeft') {
currentIndex = (currentIndex - 1 + images.length) % images.length;
rotationY += 360 / images.length;
updateGallery();
} else if (e.key === 'ArrowRight') {
currentIndex = (currentIndex + 1) % images.length;
rotationY -= 360 / images.length;
updateGallery();
}
});
// Obsługa przewijania myszą
document.addEventListener('wheel', (e) => {
if (isFlatMode) return;
if (e.deltaY > 0) {
currentIndex = (currentIndex + 1) % images.length;
rotationY -= 360 / images.length;
} else {
currentIndex = (currentIndex - 1 + images.length) % images.length;
rotationY += 360 / images.length;
}
updateGallery();
e.preventDefault();
}, { passive: false });
// Responsywność
window.addEventListener('resize', updateGallery);
// Inicjalizacja
initGallery();
</script>
</body>
</html>
Czy chciałbyś, żebym wyjaśnił lub omówił jakieś elementy tego kodu?