02Backdrop Fade Plus Image Scale-Up
While the backdrop dims, the image itself starts slightly smaller than final size and eases up to rest — a different demo from a generic dialog fade-scale, since the start scale and dim amount are both derived from the image's own aspect ratio.
Best forIn-article image enlarge views
clamp()transform: scalebackdrop opacity

<main class="stage">
<div class="scene is-demo" id="scene">
<ul class="grid" id="grid">
<li><button class="thumb" id="thumb0" type="button" aria-haspopup="dialog" data-w="280" data-h="210"><span class="thumbImg thumbImg--a"></span><span class="thumbLabel">Photo 1</span></button></li>
<li><button class="thumb" id="thumb1" type="button" aria-haspopup="dialog" data-w="200" data-h="200"><span class="thumbImg thumbImg--b"></span><span class="thumbLabel">Photo 2</span></button></li>
<li><button class="thumb" id="thumb2" type="button" aria-haspopup="dialog" data-w="180" data-h="240"><span class="thumbImg thumbImg--c"></span><span class="thumbLabel">Photo 3</span></button></li>
</ul>
<div class="backdrop" id="backdrop"></div>
<div class="lightbox" id="lightbox" role="dialog" aria-modal="true" aria-hidden="true" aria-label="View enlarged photo">
<span class="fullImg" id="fullImg"></span>
<p class="ratioNote" id="ratioNote"></p>
<button class="closeBtn" id="closeBtn" type="button">Close</button>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 변수 3개
$duration: $dur-base;
$easing: $ease-out;
$color: $subject-orange-deep;
// 계산 겹: index.html 의 fromAspect() 가 이미지 자신의 가로세로 비율을 0~1 로 정규화해
// 시작 스케일과 배경 어둡기(dim)를 같은 지점에서 함께 산출한다 — 세 사진마다 값이 다르다.
@include stage($stage-yellow);
.scene {
position: relative;
width: 320px;
height: 180px;
border-radius: $r-card;
overflow: hidden;
box-shadow: $shadow-raised;
background: linear-gradient(160deg, #fff1c2, $stage-yellow 75%);
}
.grid {
position: absolute;
inset: 0;
margin: 0;
padding: 0;
list-style: none;
display: flex;
align-items: center;
justify-content: center;
gap: $sp-4;
}
.thumb {
appearance: none;
border: none;
background: none;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
gap: $sp-1;
cursor: pointer;
&:focus-visible .thumbImg { outline: 2px solid $color; outline-offset: 2px; }
}
.thumbImg {
display: block;
width: 64px;
height: 48px;
border-radius: $r-sm;
box-shadow: $shadow-press;
&--a { background: linear-gradient(135deg, $subject-blue, $subject-mint); height: 48px; }
&--b { background: linear-gradient(135deg, $subject-pink, $subject-lilac); width: 56px; height: 56px; }
&--c { background: linear-gradient(135deg, $subject-sky, $subject-lilac); width: 48px; height: 64px; }
}
.thumbLabel {
font-size: 10px;
font-weight: 600;
color: $subject-ink;
}
.backdrop {
position: absolute;
inset: 0;
background: $subject-ink;
opacity: 0;
visibility: hidden;
pointer-events: none;
}
.lightbox {
position: absolute;
inset: 0;
display: grid;
place-items: center;
gap: $sp-2;
visibility: hidden;
}
.fullImg {
display: block;
width: 200px;
height: 150px;
border-radius: $r-card;
box-shadow: $shadow-raised;
transform-origin: center;
&--a { background: linear-gradient(135deg, $subject-blue, $subject-mint); }
&--b { background: linear-gradient(135deg, $subject-pink, $subject-lilac); width: 172px; height: 172px; }
&--c { background: linear-gradient(135deg, $subject-sky, $subject-lilac); width: 138px; height: 184px; }
}
.ratioNote {
position: absolute;
bottom: $sp-2;
left: 50%;
transform: translateX(-50%);
margin: 0;
font-size: 10px;
font-weight: 600;
color: $subject-cream;
background: rgba(#000, .4);
padding: $sp-1 $sp-2;
border-radius: $r-sm;
}
.closeBtn {
position: absolute;
top: $sp-2;
right: $sp-2;
appearance: none;
border: none;
border-radius: $r-pill;
padding: $sp-1 $sp-3;
font-size: 11px;
font-weight: 600;
color: $subject-ink;
background: rgba($subject-cream, .95);
cursor: pointer;
&:focus-visible { outline: 2px solid $color; outline-offset: 2px; }
}
@media (max-width: 340px) {
.scene { width: 220px; height: 124px; }
.fullImg { width: 140px; height: 104px; &--b { width: 118px; height: 118px; } &--c { width: 96px; height: 128px; } }
.ratioNote { font-size: 9px; }
}
@media (prefers-reduced-motion: reduce) {
// 실사용 경로 적용 — 스케일업·페이드 트윈은 index.html 의 animate() 가 reduce 시 즉시 최종 상태로 처리한다.
.closeBtn, .thumb { transition: none; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ffd23f;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.scene {
position: relative;
width: 320px;
height: 180px;
border-radius: 16px;
overflow: hidden;
box-shadow: 0 14px 24px rgba(23, 20, 26, 0.32);
background: linear-gradient(160deg, #fff1c2, #ffd23f 75%);
}
.grid {
position: absolute;
inset: 0;
margin: 0;
padding: 0;
list-style: none;
display: flex;
align-items: center;
justify-content: center;
gap: 16px;
}
.thumb {
appearance: none;
border: none;
background: none;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
gap: 4px;
cursor: pointer;
}
.thumb:focus-visible .thumbImg {
outline: 2px solid #c93000;
outline-offset: 2px;
}
.thumbImg {
display: block;
width: 64px;
height: 48px;
border-radius: 8px;
box-shadow: 0 6px 12px rgba(23, 20, 26, 0.32);
}
.thumbImg--a {
background: linear-gradient(135deg, #2f6df6, #4cd4a6);
height: 48px;
}
.thumbImg--b {
background: linear-gradient(135deg, #ff9ebb, #b9a0ff);
width: 56px;
height: 56px;
}
.thumbImg--c {
background: linear-gradient(135deg, #6ec8ff, #b9a0ff);
width: 48px;
height: 64px;
}
.thumbLabel {
font-size: 10px;
font-weight: 600;
color: #17141a;
}
.backdrop {
position: absolute;
inset: 0;
background: #17141a;
opacity: 0;
visibility: hidden;
pointer-events: none;
}
.lightbox {
position: absolute;
inset: 0;
display: grid;
place-items: center;
gap: 8px;
visibility: hidden;
}
.fullImg {
display: block;
width: 200px;
height: 150px;
border-radius: 16px;
box-shadow: 0 14px 24px rgba(23, 20, 26, 0.32);
transform-origin: center;
}
.fullImg--a {
background: linear-gradient(135deg, #2f6df6, #4cd4a6);
}
.fullImg--b {
background: linear-gradient(135deg, #ff9ebb, #b9a0ff);
width: 172px;
height: 172px;
}
.fullImg--c {
background: linear-gradient(135deg, #6ec8ff, #b9a0ff);
width: 138px;
height: 184px;
}
.ratioNote {
position: absolute;
bottom: 8px;
left: 50%;
transform: translateX(-50%);
margin: 0;
font-size: 10px;
font-weight: 600;
color: #fff7e6;
background: rgba(0, 0, 0, 0.4);
padding: 4px 8px;
border-radius: 8px;
}
.closeBtn {
position: absolute;
top: 8px;
right: 8px;
appearance: none;
border: none;
border-radius: 999px;
padding: 4px 12px;
font-size: 11px;
font-weight: 600;
color: #17141a;
background: rgba(255, 247, 230, 0.95);
cursor: pointer;
}
.closeBtn:focus-visible {
outline: 2px solid #c93000;
outline-offset: 2px;
}
@media (max-width: 340px) {
.scene {
width: 220px;
height: 124px;
}
.fullImg {
width: 140px;
height: 104px;
}
.fullImg--b {
width: 118px;
height: 118px;
}
.fullImg--c {
width: 96px;
height: 128px;
}
.ratioNote {
font-size: 9px;
}
}
@media (prefers-reduced-motion: reduce) {
.closeBtn, .thumb {
transition: none;
}
}(function () {
var OPEN_MS = 600;
var CLOSE_MS = 420;
var LOOP_MS = 2000;
var HOLD_OPEN_MS = 620;
var ASPECT_NORM_LO = 0.6;
var ASPECT_NORM_HI = 1.6;
var SCALE_FROM_MIN = 0.7;
var SCALE_FROM_MAX = 0.92;
var DIM_MAX = 0.82;
var DIM_MIN = 0.58;
var scene = document.getElementById('scene');
var backdrop = document.getElementById('backdrop');
var lightbox = document.getElementById('lightbox');
var fullImg = document.getElementById('fullImg');
var ratioNote = document.getElementById('ratioNote');
var closeBtn = document.getElementById('closeBtn');
var thumbs = [].slice.call(document.querySelectorAll('.thumb'));
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var imgClassByIdx = ['thumbImg--a', 'thumbImg--b', 'thumbImg--c'];
function clamp(v, lo, hi) { return Math.min(hi, Math.max(lo, v)); }
function easeOutCubic(t) { return 1 - Math.pow(1 - t, 3); }
// 이미지 자신의 가로세로 비율에서 시작 스케일과 배경 어둡기를 함께 계산한다 — 두 값이 같은 정규화 지점에서 나온다
function fromAspect(w, h) {
var aspect = w / h;
var norm = clamp((aspect - ASPECT_NORM_LO) / (ASPECT_NORM_HI - ASPECT_NORM_LO), 0, 1);
var scaleFrom = SCALE_FROM_MIN + (SCALE_FROM_MAX - SCALE_FROM_MIN) * norm;
var dim = DIM_MAX - (DIM_MAX - DIM_MIN) * norm;
return { aspect: aspect, scaleFrom: scaleFrom, dim: dim };
}
var open = false;
var activeIdx = 1;
var timers = [];
// reduce: 실사용 경로 적용 — 트윈 없이 최종 상태로 즉시 전환한다
function animate(duration, onFrame, onDone) {
if (reduce) { onFrame(1); if (onDone) onDone(); return; }
var start = performance.now();
function frame(now) {
var p = clamp((now - start) / duration, 0, 1);
onFrame(easeOutCubic(p));
if (p < 1) requestAnimationFrame(frame);
else if (onDone) onDone();
}
requestAnimationFrame(frame);
}
function openFrom(idx) {
if (open) return;
open = true;
var t = thumbs[idx];
var calc = fromAspect(Number(t.dataset.w), Number(t.dataset.h));
fullImg.className = 'fullImg ' + imgClassByIdx[idx];
ratioNote.textContent = 'Ratio ' + calc.aspect.toFixed(2) + ' · start scale ' + calc.scaleFrom.toFixed(2);
lightbox.style.visibility = 'visible';
lightbox.setAttribute('aria-hidden', 'false');
backdrop.style.visibility = 'visible';
animate(OPEN_MS, function (e) {
var s = calc.scaleFrom + (1 - calc.scaleFrom) * e;
fullImg.style.transform = 'scale(' + s.toFixed(4) + ')';
backdrop.style.opacity = (calc.dim * e).toFixed(3);
}, function () {
closeBtn.focus({ preventScroll: true });
});
}
function closeLightbox(idx) {
if (!open) return;
var t = thumbs[idx];
var calc = fromAspect(Number(t.dataset.w), Number(t.dataset.h));
animate(CLOSE_MS, function (e) {
var s = 1 + (calc.scaleFrom - 1) * e;
fullImg.style.transform = 'scale(' + s.toFixed(4) + ')';
backdrop.style.opacity = (calc.dim * (1 - e)).toFixed(3);
}, function () {
lightbox.style.visibility = 'hidden';
lightbox.setAttribute('aria-hidden', 'true');
backdrop.style.visibility = 'hidden';
open = false;
thumbs[idx].focus({ preventScroll: true });
});
}
function human() {
if (scene.classList.contains('is-demo')) {
scene.classList.remove('is-demo');
timers.forEach(function (id) { clearTimeout(id); clearInterval(id); });
timers = [];
}
}
thumbs.forEach(function (t, i) {
t.addEventListener('click', function () {
human();
activeIdx = i;
openFrom(i);
});
});
closeBtn.addEventListener('click', function () { human(); closeLightbox(activeIdx); });
backdrop.addEventListener('click', function () { human(); closeLightbox(activeIdx); });
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && open) { human(); closeLightbox(activeIdx); }
});
function cycle() {
activeIdx = 2;
openFrom(2);
timers.push(setTimeout(function () { closeLightbox(2); }, OPEN_MS + HOLD_OPEN_MS));
}
if (!reduce) {
cycle();
timers.push(setInterval(function () {
if (scene.classList.contains('is-demo')) cycle();
}, LOOP_MS));
}
})();import { useEffect, useRef } from 'react';
import styles from './BackdropFadeScale.module.scss';
const OPEN_MS = 600;
const CLOSE_MS = 420;
const LOOP_MS = 2000;
const HOLD_OPEN_MS = 620;
const ASPECT_NORM_LO = 0.6;
const ASPECT_NORM_HI = 1.6;
const SCALE_FROM_MIN = 0.7;
const SCALE_FROM_MAX = 0.92;
const DIM_MAX = 0.82;
const DIM_MIN = 0.58;
const THUMB_SIZES: { w: number; h: number }[] = [
{ w: 280, h: 210 },
{ w: 200, h: 200 },
{ w: 180, h: 240 },
];
export default function BackdropFadeScale() {
const sceneRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const scene0 = sceneRef.current;
if (!scene0) return undefined;
const backdrop0 = scene0.querySelector<HTMLDivElement>('.' + styles.backdrop);
const lightbox0 = scene0.querySelector<HTMLDivElement>('.' + styles.lightbox);
const fullImg0 = scene0.querySelector<HTMLSpanElement>('.' + styles.fullImg);
const ratioNote0 = scene0.querySelector<HTMLParagraphElement>('.' + styles.ratioNote);
const closeBtn0 = scene0.querySelector<HTMLButtonElement>('.' + styles.closeBtn);
const thumbs = Array.from(scene0.querySelectorAll<HTMLButtonElement>('.' + styles.thumb));
if (!backdrop0 || !lightbox0 || !fullImg0 || !ratioNote0 || !closeBtn0 || thumbs.length === 0) return undefined;
const scene = scene0;
const backdrop = backdrop0;
const lightbox = lightbox0;
const fullImg = fullImg0;
const ratioNote = ratioNote0;
const closeBtn = closeBtn0;
const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
const imgClassByIdx = [styles['thumbImg--a'], styles['thumbImg--b'], styles['thumbImg--c']];
function clamp(v: number, lo: number, hi: number) { return Math.min(hi, Math.max(lo, v)); }
function easeOutCubic(t: number) { return 1 - Math.pow(1 - t, 3); }
// 이미지 자신의 가로세로 비율에서 시작 스케일과 배경 어둡기를 함께 계산한다 — 두 값이 같은 정규화 지점에서 나온다
function fromAspect(w: number, h: number) {
const aspect = w / h;
const norm = clamp((aspect - ASPECT_NORM_LO) / (ASPECT_NORM_HI - ASPECT_NORM_LO), 0, 1);
const scaleFrom = SCALE_FROM_MIN + (SCALE_FROM_MAX - SCALE_FROM_MIN) * norm;
const dim = DIM_MAX - (DIM_MAX - DIM_MIN) * norm;
return { aspect, scaleFrom, dim };
}
let open = false;
let activeIdx = 1;
let timers: number[] = [];
// reduce: 실사용 경로 적용 — 트윈 없이 최종 상태로 즉시 전환한다
function animate(duration: number, onFrame: (e: number) => void, onDone?: () => void) {
if (reduce) { onFrame(1); if (onDone) onDone(); return; }
const start = performance.now();
function frame(now: number) {
const p = clamp((now - start) / duration, 0, 1);
onFrame(easeOutCubic(p));
if (p < 1) requestAnimationFrame(frame);
else if (onDone) onDone();
}
requestAnimationFrame(frame);
}
function openFrom(idx: number) {
if (open) return;
open = true;
const calc = fromAspect(THUMB_SIZES[idx].w, THUMB_SIZES[idx].h);
fullImg.className = styles.fullImg + ' ' + imgClassByIdx[idx];
ratioNote.textContent = '비율 ' + calc.aspect.toFixed(2) + ' · 시작 배율 ' + calc.scaleFrom.toFixed(2);
lightbox.style.visibility = 'visible';
lightbox.setAttribute('aria-hidden', 'false');
backdrop.style.visibility = 'visible';
animate(OPEN_MS, (e) => {
const s = calc.scaleFrom + (1 - calc.scaleFrom) * e;
fullImg.style.transform = 'scale(' + s.toFixed(4) + ')';
backdrop.style.opacity = (calc.dim * e).toFixed(3);
}, () => {
closeBtn.focus({ preventScroll: true });
});
}
function closeLightbox(idx: number) {
if (!open) return;
const calc = fromAspect(THUMB_SIZES[idx].w, THUMB_SIZES[idx].h);
animate(CLOSE_MS, (e) => {
const s = 1 + (calc.scaleFrom - 1) * e;
fullImg.style.transform = 'scale(' + s.toFixed(4) + ')';
backdrop.style.opacity = (calc.dim * (1 - e)).toFixed(3);
}, () => {
lightbox.style.visibility = 'hidden';
lightbox.setAttribute('aria-hidden', 'true');
backdrop.style.visibility = 'hidden';
open = false;
thumbs[idx].focus({ preventScroll: true });
});
}
function human() {
if (scene.classList.contains(styles['is-demo'])) {
scene.classList.remove(styles['is-demo']);
timers.forEach((id) => { window.clearTimeout(id); window.clearInterval(id); });
timers = [];
}
}
const thumbHandlers = thumbs.map((_, i) => () => { human(); activeIdx = i; openFrom(i); });
thumbs.forEach((t, i) => t.addEventListener('click', thumbHandlers[i]));
function onCloseClick() { human(); closeLightbox(activeIdx); }
function onBackdropClick() { human(); closeLightbox(activeIdx); }
function onKeydown(e: KeyboardEvent) {
if (e.key === 'Escape' && open) { human(); closeLightbox(activeIdx); }
}
closeBtn.addEventListener('click', onCloseClick);
backdrop.addEventListener('click', onBackdropClick);
document.addEventListener('keydown', onKeydown);
function cycle() {
activeIdx = 2;
openFrom(2);
timers.push(window.setTimeout(() => { closeLightbox(2); }, OPEN_MS + HOLD_OPEN_MS));
}
if (!reduce) {
cycle();
timers.push(window.setInterval(() => {
if (scene.classList.contains(styles['is-demo'])) cycle();
}, LOOP_MS));
}
return () => {
timers.forEach((id) => { window.clearTimeout(id); window.clearInterval(id); });
thumbs.forEach((t, i) => t.removeEventListener('click', thumbHandlers[i]));
closeBtn.removeEventListener('click', onCloseClick);
backdrop.removeEventListener('click', onBackdropClick);
document.removeEventListener('keydown', onKeydown);
};
}, []);
return (
<div className={`${styles.scene} ${styles['is-demo']}`} ref={sceneRef}>
<ul className={styles.grid}>
<li><button className={styles.thumb} type="button" aria-haspopup="dialog"><span className={`${styles.thumbImg} ${styles['thumbImg--a']}`} /><span className={styles.thumbLabel}>사진 1</span></button></li>
<li><button className={styles.thumb} type="button" aria-haspopup="dialog"><span className={`${styles.thumbImg} ${styles['thumbImg--b']}`} /><span className={styles.thumbLabel}>사진 2</span></button></li>
<li><button className={styles.thumb} type="button" aria-haspopup="dialog"><span className={`${styles.thumbImg} ${styles['thumbImg--c']}`} /><span className={styles.thumbLabel}>사진 3</span></button></li>
</ul>
<div className={styles.backdrop} />
<div className={styles.lightbox} role="dialog" aria-modal="true" aria-hidden="true" aria-label="사진 확대 보기">
<span className={styles.fullImg} />
<p className={styles.ratioNote} />
<button className={styles.closeBtn} type="button">닫기</button>
</div>
</div>
);
}02 Backdrop Fade Plus Image Scale-Up — Measured area 39.722% · moving frames 14/23Original by GODRICH · SCSS and React ship in the zip · CSS Lightbox Gallery Animation — 9 Transitions
The post this demo lives in
CSS Lightbox Gallery Animation — 9 TransitionsAmong nine css lightbox gallery ideas, one grows from the clicked thumbnail's spot, one times a downward flick to decide See all demos in this post
If you like this effect - similar demos
Transitions01 Fade & scale9 CSS Modal Animation Patterns, No Library Needed
Transitions02 Backdrop scale-back — the page behind shrinks in proportion to how far the panel has openedCart Drawer UI Patterns: 9 Motion Techniques
Transitions03 Scale fade-in — size and opacity values grow together from a smaller starting valueContext Menu UI: 9 Right-Click Menu Patterns