07Góc bookmark gập mở
Check vào thì tam giác ::after ở góc trên phải ruy băng xoay và phóng to quanh đúng góc đó bằng transform-origin, trông như tờ giấy vừa được gập mở ra.
Dùng choNút lưu bài viết, thêm vào danh sách đọc sau
clip-path 리본transform-origin 모서리rotate+scale

<main class="stage">
<label class="bookmark is-demo">
<input type="checkbox" class="bookmark__input">
<span class="bookmark__icon" aria-hidden="true">
<span class="bookmark__ribbon"></span>
<span class="bookmark__fold"></span>
<span class="bookmark__fx" aria-hidden="true">
<span class="bookmark__chip"></span>
<span class="bookmark__chip"></span>
<span class="bookmark__chip"></span>
<span class="bookmark__chip"></span>
<span class="bookmark__chip"></span>
<span class="bookmark__chip"></span>
</span>
</span>
<span class="bookmark__label">Lưu</span>
</label>
</main>@use "../../../../site/static/demo-tokens" as *;
// ── 변수 3개 ──────────────────────────────────────────
$duration: $dur-base; // 리본이 채워지는 시간
$easing: $ease-spring; // 스프링 이징
$color: $subject-cream; // 채워진 리본 색
// ── 데모 무대 ──────────────────────────────────────────
@include stage($stage-orange);
$shape: polygon(0 0, 100% 0, 100% 100%, 50% 76%, 0 100%);
.bookmark {
display: inline-flex;
align-items: center;
gap: clamp(8px, 2.6vw, 12px);
cursor: pointer;
-webkit-tap-highlight-color: transparent;
&__input { position: absolute; opacity: 0; width: 1px; height: 1px; }
&__icon { position: relative; width: 24px; height: 30px; flex: none; }
&__ribbon {
position: absolute; inset: 0;
clip-path: $shape;
background: rgba(255, 247, 230, .3);
&::after {
content: "";
position: absolute; inset: 0;
clip-path: $shape;
background: $color;
opacity: 0;
transform: scaleY(.35);
transform-origin: top; // 규칙8: 리본 세로 채움 위에서
transition: opacity $duration $easing, transform $duration $easing;
}
}
&__fold {
position: absolute; top: 0; right: 0; width: 8px; height: 8px;
clip-path: polygon(100% 0, 0 0, 100% 100%);
background: rgba(23, 20, 26, .35);
transform: scale(0) rotate(-90deg);
transform-origin: 100% 0; // 규칙8: 접힌 귀 꼭짓점 경첩
opacity: 0;
transition: opacity $duration $easing, transform $duration $easing;
}
// 한 겹: 물리 종잇조각(confetti) 파티클 — 접힌 귀(오른쪽 위 모서리)에서 발사. 좌표·페이드는 JS 가 계산한다.
&__fx { position: absolute; top: 0; left: 100%; pointer-events: none; } // 귀 꼭짓점이 원점
&__chip {
position: absolute; top: 0; left: 0;
width: 8px; height: 8px; margin: -4px 0 0 -4px;
background: $color;
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
opacity: 0;
pointer-events: none;
will-change: transform, opacity;
}
&__label { font-weight: 600; font-size: clamp(15px, 4.2vw, 18px); line-height: 1; font-family: inherit; color: $subject-ink; } // AA: 주황 무대 위 글자 5.50:1
&__input:checked ~ &__icon &__ribbon::after { opacity: 1; transform: scaleY(1); }
&__input:checked ~ &__icon &__fold { opacity: 1; transform: scale(1) rotate(0deg); }
&.is-demo &__icon &__ribbon::after { animation: ribbon-fill-loop $dur-loop $easing infinite; }
&.is-demo &__icon &__fold { animation: fold-in-loop $dur-loop $easing infinite; }
}
@keyframes ribbon-fill-loop {
0%, 20% { opacity: 0; transform: scaleY(.35); }
40%, 80% { opacity: 1; transform: scaleY(1); }
100% { opacity: 0; transform: scaleY(.35); }
}
@keyframes fold-in-loop {
0%, 20% { opacity: 0; transform: scale(0) rotate(-90deg); }
40%, 80% { opacity: 1; transform: scale(1) rotate(0deg); }
100% { opacity: 0; transform: scale(0) rotate(-90deg); }
}
// ── 접근성 ──────────────────────────────────────────
@media (prefers-reduced-motion: reduce) {
.bookmark__ribbon::after, .bookmark__fold { transition: opacity 1ms; }
.bookmark.is-demo .bookmark__icon .bookmark__ribbon::after,
.bookmark.is-demo .bookmark__icon .bookmark__fold { animation: none !important; opacity: 1; transform: none; }
.bookmark__chip { display: 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);
}
.bookmark {
display: inline-flex;
align-items: center;
gap: clamp(8px, 2.6vw, 12px);
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.bookmark__input {
position: absolute;
opacity: 0;
width: 1px;
height: 1px;
}
.bookmark__icon {
position: relative;
width: 24px;
height: 30px;
flex: none;
}
.bookmark__ribbon {
position: absolute;
inset: 0;
clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 76%, 0 100%);
background: rgba(255, 247, 230, 0.3);
}
.bookmark__ribbon::after {
content: "";
position: absolute;
inset: 0;
clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 76%, 0 100%);
background: #fff7e6;
opacity: 0;
transform: scaleY(0.35);
transform-origin: top;
transition: opacity 300ms cubic-bezier(0.2, 0.8, 0.2, 1), transform 300ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.bookmark__fold {
position: absolute;
top: 0;
right: 0;
width: 8px;
height: 8px;
clip-path: polygon(100% 0, 0 0, 100% 100%);
background: rgba(23, 20, 26, 0.35);
transform: scale(0) rotate(-90deg);
transform-origin: 100% 0;
opacity: 0;
transition: opacity 300ms cubic-bezier(0.2, 0.8, 0.2, 1), transform 300ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.bookmark__fx {
position: absolute;
top: 0;
left: 100%;
pointer-events: none;
}
.bookmark__chip {
position: absolute;
top: 0;
left: 0;
width: 8px;
height: 8px;
margin: -4px 0 0 -4px;
background: #fff7e6;
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
opacity: 0;
pointer-events: none;
will-change: transform, opacity;
}
.bookmark__label {
font-weight: 600;
font-size: clamp(15px, 4.2vw, 18px);
line-height: 1;
font-family: inherit;
color: #17141a;
}
.bookmark__input:checked ~ .bookmark__icon .bookmark__ribbon::after {
opacity: 1;
transform: scaleY(1);
}
.bookmark__input:checked ~ .bookmark__icon .bookmark__fold {
opacity: 1;
transform: scale(1) rotate(0deg);
}
.bookmark.is-demo .bookmark__icon .bookmark__ribbon::after {
animation: ribbon-fill-loop 2s cubic-bezier(0.2, 0.8, 0.2, 1) infinite;
}
.bookmark.is-demo .bookmark__icon .bookmark__fold {
animation: fold-in-loop 2s cubic-bezier(0.2, 0.8, 0.2, 1) infinite;
}
@keyframes ribbon-fill-loop {
0%, 20% {
opacity: 0;
transform: scaleY(0.35);
}
40%, 80% {
opacity: 1;
transform: scaleY(1);
}
100% {
opacity: 0;
transform: scaleY(0.35);
}
}
@keyframes fold-in-loop {
0%, 20% {
opacity: 0;
transform: scale(0) rotate(-90deg);
}
40%, 80% {
opacity: 1;
transform: scale(1) rotate(0deg);
}
100% {
opacity: 0;
transform: scale(0) rotate(-90deg);
}
}
@media (prefers-reduced-motion: reduce) {
.bookmark__ribbon::after, .bookmark__fold {
transition: opacity 1ms;
}
.bookmark.is-demo .bookmark__icon .bookmark__ribbon::after,
.bookmark.is-demo .bookmark__icon .bookmark__fold {
animation: none !important;
opacity: 1;
transform: none;
}
.bookmark__chip {
display: none;
}
}// 한 겹: 종이 조각(confetti) 물리 파티클 — Lưu 체크 순간 접힌 귀(오른쪽 위 모서리)에서
// 다이아몬드 종잇조각이 흩어진다. 각 조각은 질량·감쇠(-k/m·v)·중력을 매 프레임 준암시 오일러
// 적분으로 받아 날아갔다 멈춘다. transform 은 JS 가 계산해 기입한다(키이프레임 아님).
(function () {
var ps = [].slice.call(document.querySelectorAll('.bookmark__chip'));
var reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
var alive = false, raf = 0, last = 0;
function fire() {
if (reduce || !ps.length) return;
var now = performance.now();
for (var i = 0; i < ps.length; i++) {
var m = .7 + Math.random() * .9; // 개별 질량 0.7~1.6
var ang = -Math.PI / 4 + (Math.random() - .5) * 2.8; // 바깥쪽(위·오른쪽) 부채꼴 ±80°
var v0 = (110 + Math.random() * 80) * (1.15 - m * .2); // 무거울수록 느게 출발
ps[i]._p = { x: 0, y: 0, vx: Math.cos(ang) * v0, vy: Math.sin(ang) * v0,
m: m, k: 3.2, g: 320, rot: (Math.random() - .5) * 40, spin: (Math.random() - .5) * 960,
s: .4 + m * .3, born: now + i * 20, life: 700 + Math.random() * 300 };
}
if (!alive) { alive = true; last = now; raf = requestAnimationFrame(step); }
}
function step(t) {
var dt = Math.min((t - last) / 1000, .05); last = t; // 탭 복귀 시 폭주 방지 클램프
var any = false;
for (var i = 0; i < ps.length; i++) {
var el = ps[i], p = el._p; if (!p) continue;
var age = t - p.born;
if (age < 0) { any = true; continue; } // 방출 전 지연(순차 분사)
if (age >= p.life) { el.style.opacity = '0'; el._p = null; continue; } // 수명 끝 → 그 자리에 정지
p.vx += (-p.k / p.m * p.vx) * dt; // 감쇠 가속도 = -k/m·v
p.vy += (p.g - p.k / p.m * p.vy) * dt; // 중력 가속도 = g (질량 무관)
p.x += p.vx * dt; p.y += p.vy * dt; p.rot += p.spin * dt;
var o = age / p.life; // 수명 후반 45%에서 페이드아웃
el.style.opacity = o < .55 ? '1' : (1 - (o - .55) / .45).toFixed(3);
el.style.transform = 'translate(' + p.x.toFixed(1) + 'px,' + p.y.toFixed(1) + 'px) rotate(' + p.rot.toFixed(1) + 'deg) scale(' + p.s.toFixed(3) + ')';
any = true;
}
if (any) raf = requestAnimationFrame(step); else alive = false; // 전부 정지하면 루프 종료
}
// 트리거 1: 실제 클릭 — 체크되는 순간(Lưu 순간) 발사
document.querySelectorAll('.bookmark').forEach(function (b) {
var inp = b.querySelector('.bookmark__input');
if (inp) inp.addEventListener('change', function () { b.classList.remove('is-demo'); if (inp.checked) fire(); });
if (inp) inp.addEventListener('pointerdown', function () { b.classList.remove('is-demo'); });
});
// 트리거 2: 데모 루프 — 귀 접힘(2s 루프의 40% ≈ 800ms)에 맞춰 발사
function demoShot() {
document.querySelectorAll('.bookmark').forEach(function (b) {
if (b.classList.contains('is-demo')) setTimeout(fire, 800);
});
}
setInterval(demoShot, 2000);
demoShot();
})();import { useCallback, useEffect, useRef, useState } from "react";
import type { ChangeEvent, CSSProperties } from "react";
import styles from "./BookmarkFold.module.scss";
export type BookmarkFoldProps = {
duration?: number;
easing?: string;
color?: string;
defaultSaved?: boolean;
onChange?: (saved: boolean) => void;
};
type Vars = CSSProperties & { "--duration"?: string; "--easing"?: string; "--color"?: string };
/** 종잇조각 1개의 물성 — 질량·감쇠·중력으로 날아갔다 멈춘다 (귀 꼭짓점 기준 바깥 부채꼴) */
type Particle = {
x: number; y: number; vx: number; vy: number;
m: number; k: number; g: number;
rot: number; spin: number; s: number;
born: number; life: number;
};
const CHIP_COUNT = 6;
/** 질량-감쇠 물리 초기 상태. 감쇠 = -k/m·v, 중력 = g. 접힌 귀에서 위·오른쪽 부채꼴로 흩어진다. */
function spawn(now: number, i: number): Particle {
const m = 0.7 + Math.random() * 0.9; // 개별 질량 0.7~1.6
const ang = -Math.PI / 4 + (Math.random() - 0.5) * 2.8; // 바깥쪽(위·오른쪽) 부채꼴 ±80°
const v0 = (110 + Math.random() * 80) * (1.15 - m * 0.2); // 무거울수록 느게 출발
return {
x: 0, y: 0,
vx: Math.cos(ang) * v0, vy: Math.sin(ang) * v0,
m, k: 3.2, g: 320,
rot: (Math.random() - 0.5) * 40, spin: (Math.random() - 0.5) * 960,
s: 0.4 + m * 0.3,
born: now + i * 20, life: 700 + Math.random() * 300, // 순차 분사 + 수명 랜덤
};
}
export default function BookmarkFold({ duration = 300, easing = "cubic-bezier(.2,.8,.2,1)", color = "#fff7e6", defaultSaved = false, onChange }: BookmarkFoldProps) {
const [saved, setSaved] = useState(defaultSaved);
const [burstKey, setBurstKey] = useState(0);
const iconRef = useRef<HTMLSpanElement>(null);
const vars: Vars = { "--duration": `${duration}ms`, "--easing": easing, "--color": color };
const fire = useCallback(() => setBurstKey((k) => k + 1), []);
// 준암시 오일러 적분 루프 — rAF 안에서 좌표를 계산해 transform 에 쓴다 (keyframes 하드코딩 아님)
useEffect(() => {
if (!burstKey) return;
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
const icon = iconRef.current;
if (!icon) return;
const els = Array.from(icon.querySelectorAll<HTMLElement>(`.${styles.chip}`));
if (!els.length) return;
const now = performance.now();
const ps: (Particle | null)[] = els.map((_, i) => spawn(now, i));
let raf = 0, last = now;
const step = (t: number) => {
const dt = Math.min((t - last) / 1000, 0.05); // 탭 복귀 시 폭주 방지 클램프
last = t;
let any = false;
for (let i = 0; i < els.length; i++) {
const el = els[i], p = ps[i]; if (!p) continue;
const age = t - p.born;
if (age < 0) { any = true; continue; } // 방출 전 지연
if (age >= p.life) { el.style.opacity = "0"; ps[i] = null; continue; } // 수명 끝 → 정지
p.vx += (-p.k / p.m * p.vx) * dt; // 감쇠 = -k/m·v
p.vy += (p.g - p.k / p.m * p.vy) * dt; // 중력 + 감쇠
p.x += p.vx * dt; p.y += p.vy * dt; p.rot += p.spin * dt;
const o = age / p.life;
el.style.opacity = o < 0.55 ? "1" : (1 - (o - 0.55) / 0.45).toFixed(3);
el.style.transform =
`translate(${p.x.toFixed(1)}px,${p.y.toFixed(1)}px) rotate(${p.rot.toFixed(1)}deg) scale(${p.s.toFixed(3)})`;
any = true;
}
if (any) raf = requestAnimationFrame(step); // 전부 정지하면 루프 종료
};
raf = requestAnimationFrame(step);
return () => cancelAnimationFrame(raf);
}, [burstKey]);
return (
<label className={styles.bookmark} style={vars}>
<input
type="checkbox"
className={styles.input}
checked={saved}
onChange={(e: ChangeEvent<HTMLInputElement>) => { setSaved(e.target.checked); if (e.target.checked) fire(); onChange?.(e.target.checked); }}
/>
<span className={styles.icon} aria-hidden="true" ref={iconRef}>
<span className={styles.ribbon}>
<span className={`${styles.ribbonFill} ${saved ? styles.isSaved : ""}`} />
</span>
<span className={`${styles.fold} ${saved ? styles.isSaved : ""}`} />
<span className={styles.fx} aria-hidden="true">
{Array.from({ length: CHIP_COUNT }, (_, i) => (
<span key={`${burstKey}-${i}`} className={styles.chip} aria-hidden="true" />
))}
</span>
</span>
<span className={styles.label}>저장</span>
</label>
);
}07 Góc bookmark gập mở — Diện tích đo được 0.758% · khung hình chuyển động 17/23Nguyên tác GODRICH · SCSS và React nằm trong tệp zip · 9 CSS Heart Like Animations — dán 1 dòng là chạy
Bài viết chứa demo này
9 CSS Heart Like Animations — dán 1 dòng là chạyChín css heart like animation cho nút thích, đánh giá sao và các nút phản hồi kiểu vỗ tay, bookmark, emoji được gom vào Xem tất cả demo trong bài này

