*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
:root { --bg: #070a12; --text: #f0f4fb; --muted: #8a95a8; --accent: #86e8ff; --border: #263249; }
body { background: var(--bg); color: var(--text); font-family: 'Inter', 'SF Pro Display', system-ui, sans-serif; min-height: 100vh; }
.header { text-align: center; padding: 5rem 2rem 2rem; }
.eyebrow { display: inline-block; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.18em; color: var(--accent); margin-bottom: 1rem; }
h1 { font-size: clamp(2rem, 5vw, 3rem); font-weight: 700; letter-spacing: -0.02em; }
.subtitle { font-size: clamp(0.9rem, 2vw, 1.05rem); color: var(--muted); max-width: 460px; margin: 0.75rem auto 0; line-height: 1.6; }
/* Gallery */
.gallery { max-width: 900px; margin: 0 auto; padding: 0 2rem; }
.hero-area { margin-bottom: 1.5rem; }
.hero-image {
width: 100%; aspect-ratio: 16/9; border-radius: 18px;
background: linear-gradient(135deg, hsl(var(--hue,200) 50% 12%), hsl(var(--hue,200) 65% 22%), hsl(calc(var(--hue,200) + 50) 50% 18%));
display: flex; flex-direction: column; align-items: center; justify-content: center;
position: relative; overflow: hidden;
}
.hero-number {
font-size: 6rem; font-weight: 700; color: rgba(255,255,255,0.06); line-height: 1;
}
.hero-label {
font-size: 1.1rem; font-weight: 600; color: rgba(255,255,255,0.7);
margin-top: -0.5rem;
}
/* Thumbnails */
.thumb-strip {
display: flex; gap: 0.6rem; overflow-x: auto;
padding: 0.5rem 0 1.5rem; scroll-snap-type: x mandatory;
-ms-overflow-style: none; scrollbar-width: none;
}
.thumb-strip::-webkit-scrollbar { display: none; }
.thumb {
flex-shrink: 0; width: 100px; height: 70px; border-radius: 10px;
background: linear-gradient(135deg, hsl(var(--hue,200) 40% 12%), hsl(var(--hue,200) 55% 20%));
border: 2px solid transparent; cursor: pointer;
display: flex; align-items: center; justify-content: center;
font: 700 1.2rem/1 'Inter', system-ui, sans-serif;
color: rgba(255,255,255,0.15);
transition: border-color 0.25s, transform 0.25s;
scroll-snap-align: center;
}
.thumb:hover { border-color: rgba(134,232,255,0.3); transform: translateY(-2px); }
.thumb.active { border-color: var(--accent); box-shadow: 0 0 16px rgba(134,232,255,0.15); }
/* View Transitions */
::view-transition-old(hero-img) { animation: hero-out 0.3s ease-in; }
::view-transition-new(hero-img) { animation: hero-in 0.35s ease-out; }
@keyframes hero-out { to { opacity: 0; transform: scale(0.96); } }
@keyframes hero-in { from { opacity: 0; transform: scale(1.04); } }
.footer { text-align: center; padding: 1.5rem 2rem 3rem; }
.btn-back {
display: inline-block; padding: 0.7rem 2rem; border-radius: 999px;
border: 1px solid rgba(134,232,255,0.3); color: var(--accent); text-decoration: none;
font: 600 0.85rem/1 'Inter', system-ui, sans-serif; transition: all 0.25s;
}
.btn-back:hover { background: rgba(134,232,255,0.08); border-color: var(--accent); }
@media (max-width: 640px) {
.thumb { width: 80px; height: 56px; }
.gallery { padding: 0 1rem; }
}
if (!window.MotionPreference) {
const __mql = window.matchMedia("(prefers-reduced-motion: reduce)");
const __listeners = new Set();
const MotionPreference = {
prefersReducedMotion() {
return __mql.matches;
},
setOverride(value) {
const reduced = Boolean(value);
document.documentElement.classList.toggle("reduced-motion", reduced);
window.dispatchEvent(new CustomEvent("motion-preference", { detail: { reduced } }));
for (const listener of __listeners) {
try {
listener({ reduced, override: reduced, systemReduced: __mql.matches });
} catch {}
}
},
onChange(listener) {
__listeners.add(listener);
try {
listener({
reduced: __mql.matches,
override: null,
systemReduced: __mql.matches,
});
} catch {}
return () => __listeners.delete(listener);
},
getState() {
return { reduced: __mql.matches, override: null, systemReduced: __mql.matches };
},
};
window.MotionPreference = MotionPreference;
}
function prefersReducedMotion() {
return window.MotionPreference.prefersReducedMotion();
}
function initDemoShell() {
// No-op shim in imported standalone snippets.
}
initDemoShell({ title: 'Image Gallery Transitions', category: 'transitions', tech: ['view-transitions-api', 'crossfade'] });
const supportsVT = typeof document.startViewTransition === 'function';
const heroImage = document.getElementById('hero-image');
const heroNumber = document.getElementById('hero-number');
const heroLabel = document.getElementById('hero-label');
const thumbs = document.querySelectorAll('.thumb');
let currentIndex = 0;
function selectImage(index) {
if (index === currentIndex) return;
const thumb = document.querySelector(`.thumb[data-index="${index}"]`);
if (!thumb) return;
const hue = thumb.dataset.hue;
const label = thumb.dataset.label;
const num = String(index + 1).padStart(2, '0');
const updateDOM = () => {
heroImage.style.setProperty('--hue', hue);
heroNumber.textContent = num;
heroLabel.textContent = label;
thumbs.forEach((t, i) => t.classList.toggle('active', i === index));
currentIndex = index;
};
if (supportsVT && !prefersReducedMotion()) {
document.startViewTransition(updateDOM);
} else {
updateDOM();
}
}
// Click handlers
thumbs.forEach((thumb) => {
thumb.addEventListener('click', () => {
selectImage(parseInt(thumb.dataset.index, 10));
});
});
// Keyboard navigation
document.addEventListener('keydown', (e) => {
if (e.key === 'ArrowRight') {
selectImage(Math.min(currentIndex + 1, thumbs.length - 1));
} else if (e.key === 'ArrowLeft') {
selectImage(Math.max(currentIndex - 1, 0));
}
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Gallery Transitions — stealthisdesign</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header class="header">
<span class="eyebrow">Demo 14</span>
<h1>Image Gallery</h1>
<p class="subtitle">Click a thumbnail to see a smooth crossfade with scale using View Transitions. The hero image morphs between selections.</p>
</header>
<main class="gallery">
<div class="hero-area">
<div class="hero-image" id="hero-image" style="view-transition-name: hero-img; --hue: 200;">
<span class="hero-number" id="hero-number">01</span>
<span class="hero-label" id="hero-label">Aurora Borealis</span>
</div>
</div>
<div class="thumb-strip" id="thumb-strip">
<button class="thumb active" data-index="0" data-hue="200" data-label="Aurora Borealis" style="--hue: 200;"><span>01</span></button>
<button class="thumb" data-index="1" data-hue="270" data-label="Nebula Cloud" style="--hue: 270;"><span>02</span></button>
<button class="thumb" data-index="2" data-hue="330" data-label="Sunset Gradient" style="--hue: 330;"><span>03</span></button>
<button class="thumb" data-index="3" data-hue="45" data-label="Golden Hour" style="--hue: 45;"><span>04</span></button>
<button class="thumb" data-index="4" data-hue="160" data-label="Deep Forest" style="--hue: 160;"><span>05</span></button>
<button class="thumb" data-index="5" data-hue="15" data-label="Ember Glow" style="--hue: 15;"><span>06</span></button>
<button class="thumb" data-index="6" data-hue="240" data-label="Midnight Sky" style="--hue: 240;"><span>07</span></button>
<button class="thumb" data-index="7" data-hue="90" data-label="Spring Meadow" style="--hue: 90;"><span>08</span></button>
</div>
</main>
<div class="footer">
<a href="/" class="btn-back">Back to Showcase</a>
</div>
<script src="script.js"></script>
</body>
</html>