06헤더 줄어들기
스크롤하면 고정 헤더가 얇아지고 로고가 작아진다.
쓰임랜딩·블로그 헤더
64→48px로고만그림자 추가

<main class="stage">
<header class="head is-demo">
<span class="head__logo">GODRICH</span>
<nav class="head__nav" aria-hidden="true">
<span></span><span></span><span></span>
</nav>
</header>
<div class="page">
<p class="page__line"></p>
<p class="page__line"></p>
<p class="page__line short"></p>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// ── 변수 3개. 변형은 이것만 바꾼다 (값은 토큰에서 받는다) ──────
$tall: 64px; // 처음 헤더 높이
$short-scale: .75; // 줄어든 비율 (64px → 48px ≈ .75)
$color: $subject-ink; // 헤더 배경 (yellow 무대라 ink)
// ── 데모 무대 (zip 에서 지워도 된다) ──────────────────────────
html, body { margin: 0; overflow: hidden; }
.stage {
min-height: 100vh;
margin: 0;
background: $stage-yellow;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
}
// ── 헤더: 높이 대신 transform: scaleY 로 "줄어든다" ────────────
// (height 는 애니메이션하면 레이아웃을 다시 계산한다 — 함정 섹션 참고)
.head {
position: sticky;
top: 0;
height: $tall;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 clamp(16px, 5vw, 24px);
background: $color;
transform-origin: top; // 규칙8: 헤더가 top에서 얇아짐
&__logo { color: #fff; font-weight: 800; font-size: 18px; line-height: 1; font-family: inherit; letter-spacing: .04em; }
&__nav { display: flex; gap: 10px; span { width: 26px; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, .35); } }
// ── 실제 사용 코드: 문서 스크롤이 진행되는 동안 얇아진다 ──
@supports (animation-timeline: scroll()) {
animation: shrink-header linear both;
animation-timeline: scroll(root);
animation-range: 0 200px;
}
@supports not (animation-timeline: scroll()) {
transform: none;
}
}
@keyframes shrink-header {
from { transform: scaleY(1); }
to { transform: scaleY($short-scale); }
}
// ── 데모(.is-demo): 스크롤 대신 2초 루프(줄었다 늘었다)로 흉내 ──
.head.is-demo {
animation: shrink-loop $dur-loop ease-in-out infinite;
}
@keyframes shrink-loop {
0% { transform: scaleY(1); }
50% { transform: scaleY($short-scale); }
100% { transform: scaleY(1); }
}
// ── 배경: 문서처럼 보이는 자리 ─────────────────────────
.page { padding: 28px 24px 0; }
.page__line {
height: 12px;
margin: 0 0 14px;
border-radius: 4px;
background: rgba(23, 20, 26, .14);
&.short { width: 60%; }
}
// ── 접근성: 움직임 줄이기 설정이면 즉시 줄인 상태로 고정 ────────
@media (prefers-reduced-motion: reduce) {
.head, .head.is-demo { animation: none !important; transform: scaleY($short-scale); }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
min-height: 100vh;
margin: 0;
background: #ffd23f;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
}
.head {
position: sticky;
top: 0;
height: 64px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 clamp(16px, 5vw, 24px);
background: #17141a;
transform-origin: top;
}
.head__logo {
color: #fff;
font-weight: 800;
font-size: 18px;
line-height: 1;
font-family: inherit;
letter-spacing: 0.04em;
}
.head__nav {
display: flex;
gap: 10px;
}
.head__nav span {
width: 26px;
height: 8px;
border-radius: 4px;
background: rgba(255, 255, 255, 0.35);
}
@supports (animation-timeline: scroll()) {
.head {
animation: shrink-header linear both;
animation-timeline: scroll(root);
animation-range: 0 200px;
}
}
@supports not (animation-timeline: scroll()) {
.head {
transform: none;
}
}
@keyframes shrink-header {
from {
transform: scaleY(1);
}
to {
transform: scaleY(0.75);
}
}
.head.is-demo {
animation: shrink-loop 2s ease-in-out infinite;
}
@keyframes shrink-loop {
0% {
transform: scaleY(1);
}
50% {
transform: scaleY(0.75);
}
100% {
transform: scaleY(1);
}
}
.page {
padding: 28px 24px 0;
}
.page__line {
height: 12px;
margin: 0 0 14px;
border-radius: 4px;
background: rgba(23, 20, 26, 0.14);
}
.page__line.short {
width: 60%;
}
@media (prefers-reduced-motion: reduce) {
.head, .head.is-demo {
animation: none !important;
transform: scaleY(0.75);
}
}import type { CSSProperties, ReactNode } from "react";
import styles from "./ShrinkingHeader.module.scss";
export type ShrinkingHeaderProps = {
logo: string;
children?: ReactNode;
/** 처음 헤더 높이 (기본 64px) */
tall?: number;
/** 줄어든 비율 (기본 .75 → 64px 기준 48px) */
shortScale?: number;
/** 헤더 배경 (기본 어두운색) */
color?: string;
className?: string;
};
type Vars = CSSProperties & { "--tall"?: string; "--short-scale"?: number; "--color"?: string };
export default function ShrinkingHeader({
logo,
children,
tall = 64,
shortScale = 0.75,
color = "#17141a",
className = "",
}: ShrinkingHeaderProps) {
const vars: Vars = { "--tall": `${tall}px`, "--short-scale": shortScale, "--color": color };
return (
<header className={`${styles.head} ${className}`} style={vars}>
<span className={styles.logo}>{logo}</span>
<nav className={styles.nav}>{children}</nav>
</header>
);
}06 헤더 줄어들기 — 측정 누적면적 7.342% · 움직인 프레임 23/23GODRICH 원작 · zip 에 SCSS·React 포함 · CSS 스크롤 애니메이션 9종 — AOS·GSAP 없이 JS 0줄로
이 데모가 속한 글
CSS 스크롤 애니메이션 9종 — AOS·GSAP 없이 JS 0줄로CSS 스크롤 애니메이션 아홉 개를 모았습니다. AOS·GSAP 없이 브라우저 내장 animation-timeline 하나로 스크롤 위치 자체를 애니메이션 시계로 씁니다. JS는 0줄이고, 격자에서는 아홉 개 효과가 이 글의 데모 전부 보기


