07層の値ごとに紙を一枚ずつ重ねたような文字
影ごとに色と距離の値を変え、層の値が増えるほど紙を何枚も重ねたように見える。
使いどころカードニュースのタイトル
PAPER_LAYER_COUNTbuildPaperShadowrenderPaper

<main class="stage">
<div class="pp is-demo" id="pp">
<p class="pp__badge"><span class="pp__badgeLabel">紙の層</span> <span class="pp__badgeValue" id="ppValue">1</span></p>
<h1 class="pp__word" id="ppWord">紙</h1>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 핵심: 층 값(n) 하나로 색·거리 값이 다른 종이 층을 n 장 쌓는다. n 이 늘수록 종이를
// 여러 장 겹쳐 놓은 것처럼 보이고, 줄면 한두 장만 남은 듯 보인다.
$duration: $dur-loop;
$easing: linear;
$color: $subject-ink;
@include stage($stage-orange);
.pp {
display: grid;
gap: $sp-4;
justify-items: center;
text-align: center;
}
.pp__badge {
margin: 0;
padding: $sp-1 $sp-3;
border-radius: $r-pill;
background: rgba(23, 20, 26, .12);
color: $subject-ink;
font-weight: 700;
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.pp__word {
margin: 0;
font-weight: 800;
font-size: clamp(68px, 22vw, 128px);
line-height: 1;
white-space: nowrap;
color: $color;
will-change: text-shadow;
}
@media (max-width: 340px) {
.pp__word { font-size: clamp(48px, 24vw, 84px); }
}
@media (prefers-reduced-motion: reduce) {
.pp__word { transition: none; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ff4d1f;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.pp {
display: grid;
gap: 16px;
justify-items: center;
text-align: center;
}
.pp__badge {
margin: 0;
padding: 4px 12px;
border-radius: 999px;
background: rgba(23, 20, 26, 0.12);
color: #17141a;
font-weight: 700;
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.pp__word {
margin: 0;
font-weight: 800;
font-size: clamp(68px, 22vw, 128px);
line-height: 1;
white-space: nowrap;
color: #17141a;
will-change: text-shadow;
}
@media (max-width: 340px) {
.pp__word {
font-size: clamp(48px, 24vw, 84px);
}
}
@media (prefers-reduced-motion: reduce) {
.pp__word {
transition: none;
}
}(function () {
var PAPER_LAYER_COUNT = 6;
var OFFSET_STEP_PX = 12;
var PERIOD_MS = 1000;
var word = document.getElementById('ppWord');
var value = document.getElementById('ppValue');
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
// 층 값(n) 하나로 색·거리 값이 다른 紙 층을 n 장 쌓는다 — n 이 늘수록 종이가
// 여러 장 겹친 것처럼 보인다
function buildPaperShadow(n) {
var parts = [];
for (var i = 1; i <= n; i++) {
var d = (i * OFFSET_STEP_PX).toFixed(2);
var warm = i % 2 === 0;
var sheet = warm ? 'rgba(255,247,230,.92)' : 'rgba(246,238,222,.92)';
parts.push(d + 'px ' + d + 'px 0 ' + sheet);
parts.push(d + 'px ' + (Number(d) + 1.4).toFixed(2) + 'px 2px rgba(23,20,26,' + (0.22 - i * 0.02).toFixed(2) + ')');
}
return parts.join(', ');
}
function renderPaper(n) {
word.style.textShadow = buildPaperShadow(n);
value.textContent = String(n);
}
var startTime = null;
function loop(now) {
if (startTime === null) startTime = now;
var t = (now - startTime) % PERIOD_MS;
var phase = (Math.sin((t / PERIOD_MS) * Math.PI * 2 - Math.PI / 2) + 1) / 2;
var n = 1 + Math.round(phase * (PAPER_LAYER_COUNT - 1));
renderPaper(n);
requestAnimationFrame(loop);
}
if (reduce) {
renderPaper(PAPER_LAYER_COUNT);
} else {
requestAnimationFrame(loop);
}
})();// TextShadowPaperStackLayer — vanilla 판(run/412/demo/07-text-shadow-paper-stack-layer/index.html) 의 React 포트.
// 층 값(n) 하나로 색·거리 값이 다른 종이 층을 n 장 쌓는다 — n 이 늘수록 종이가
// 여러 장 겹친 것처럼 보인다.
import { useEffect, useRef, useState } from "react";
import styles from "./TextShadowPaperStackLayer.module.scss";
type Box<T> = { current: T };
const PAPER_LAYER_COUNT = 6;
const OFFSET_STEP_PX = 12;
const PERIOD_MS = 1000;
function buildPaperShadow(n: number): string {
const parts: string[] = [];
for (let i = 1; i <= n; i++) {
const d = (i * OFFSET_STEP_PX).toFixed(2);
const warm = i % 2 === 0;
const sheet = warm ? "rgba(255,247,230,.92)" : "rgba(246,238,222,.92)";
parts.push(d + "px " + d + "px 0 " + sheet);
parts.push(d + "px " + (Number(d) + 1.4).toFixed(2) + "px 2px rgba(23,20,26," + (0.22 - i * 0.02).toFixed(2) + ")");
}
return parts.join(", ");
}
export default function TextShadowPaperStackLayer() {
const wordRef = useRef<HTMLHeadingElement | null>(null);
const valueRef = useRef<HTMLSpanElement | null>(null);
const t0Ref = useRef<number>(0) as Box<number>;
const frameRef = useRef<number>(0) as Box<number>;
const [demo] = useState(true);
const [reduce, setReduce] = useState(false);
function render(n: number): void {
const word = wordRef.current;
const value = valueRef.current;
if (!word || !value) return;
word.style.textShadow = buildPaperShadow(n);
value.textContent = String(n);
}
useEffect(() => {
setReduce(window.matchMedia("(prefers-reduced-motion: reduce)").matches);
}, []);
useEffect(() => {
if (reduce) {
render(PAPER_LAYER_COUNT);
return;
}
function loop(now: number): void {
if (t0Ref.current === 0) t0Ref.current = now;
const t = (now - t0Ref.current) % PERIOD_MS;
const phase = (Math.sin((t / PERIOD_MS) * Math.PI * 2 - Math.PI / 2) + 1) / 2;
const n = 1 + Math.round(phase * (PAPER_LAYER_COUNT - 1));
render(n);
frameRef.current = requestAnimationFrame(loop);
}
frameRef.current = requestAnimationFrame(loop);
return () => cancelAnimationFrame(frameRef.current);
}, [reduce]);
const cls = [styles.pp, demo ? styles.isDemo : ""].filter(Boolean).join(" ");
return (
<main className={styles.stage}>
<div className={cls}>
<p className={styles.badge}><span>종이 층</span> <span ref={valueRef}>1</span></p>
<h1 className={styles.word} ref={wordRef}>종이</h1>
</div>
</main>
);
}07 層の値ごとに紙を一枚ずつ重ねたような文字 — 計測 累積面積 11.642% · 動いたフレーム 18/23GODRICH オリジナル · SCSS と React は zip に同梱 · css text-shadow 9パターン — 影の値で立つ文字
このデモが属する記事
css text-shadow 9パターン — 影の値で立つ文字css text-shadowでは、影とは光が消えた場所のはずなのに、この九つの文字は影だけで輝く — 1番は重ねた層の値で立体を立て、5番はずれた色の値で揺らし、9番はカーソルが乗った瞬間その深さの値を押し上げる。 この記事のデモをすべて見る


