02말풍선 모핑 — 점 세 개가 하나의 말풍선 크기로 합쳐지는 전환
입력 중 표시가 끝난 상태가 되면 점 세 개의 전체 너비값이 말풍선 하나의 너비값으로 보간되고, 보간이 끝나는 시점에 맞춰 메시지 내용이 자리를 이어받습니다.
쓰임메신저 앱의 실시간 대화 화면, 챗봇이 아닌 실사용자 채팅
setPropertyrequestAnimationFrameprefers-reduced-motion

<main class="stage">
<section class="panel">
<div class="row">
<span class="avatar" aria-hidden="true"></span>
<div class="bubble" id="bubble" role="status" aria-live="polite">
<span class="dots" id="dots">
<span class="dot"></span><span class="dot"></span><span class="dot"></span>
</span>
<span class="msg" id="msg">메시지 도착</span>
</div>
</div>
</section>
</main>@use "../../../../site/static/demo-tokens" as *;
@include stage($stage-yellow);
.panel { display: flex; flex-direction: column; align-items: center; gap: $sp-4; }
.row { display: flex; align-items: center; gap: $sp-3; }
.avatar { width: 32px; height: 32px; border-radius: $r-pill; background: $subject-ink; flex: none; }
// --w 는 점 3개의 합산 폭에서 메시지 폭까지 JS 가 매 프레임 재계산해 넣는 값(px, 단위 없이 저장)
.bubble {
position: relative;
height: 44px;
width: calc(var(--w, 56) * 1px);
border-radius: $r-card;
background: $subject-ink;
overflow: hidden;
}
.dots, .msg {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
gap: $sp-2;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: $subject-cream;
}
.msg {
color: $subject-cream;
font-size: 13px;
white-space: nowrap;
padding: 0 $sp-3;
opacity: 0;
}
@media (max-width: 340px) {
.bubble { height: 38px; }
.avatar { width: 26px; height: 26px; }
.msg { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
.dots, .msg { 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);
}
.panel {
display: flex;
flex-direction: column;
align-items: center;
gap: 16px;
}
.row {
display: flex;
align-items: center;
gap: 12px;
}
.avatar {
width: 32px;
height: 32px;
border-radius: 999px;
background: #17141a;
flex: none;
}
.bubble {
position: relative;
height: 44px;
width: calc(var(--w, 56) * 1px);
border-radius: 16px;
background: #17141a;
overflow: hidden;
}
.dots, .msg {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #fff7e6;
}
.msg {
color: #fff7e6;
font-size: 13px;
white-space: nowrap;
padding: 0 12px;
opacity: 0;
}
@media (max-width: 340px) {
.bubble {
height: 38px;
}
.avatar {
width: 26px;
height: 26px;
}
.msg {
font-size: 12px;
}
}
@media (prefers-reduced-motion: reduce) {
.dots, .msg {
transition: none;
}
}// 말풍선 모핑 — 점 세 개의 합산 너비 값을 말풍선 하나의 너비 값으로 보간한다.
// 계산 겹: 경과 비율 → 너비 값(px) 재계산 → CSS 커스텀 프로퍼티(--w)에 반영. 자동 재생만, 실사용자 리스너 없음.
(function () {
var bubble = document.getElementById('bubble');
var dots = document.getElementById('dots');
var msg = document.getElementById('msg');
if (!bubble || !dots || !msg) return;
var DOT_W = 56;
var MSG_W = 168;
var CYCLE_MS = 2000;
var MORPH_START = 0.10 * CYCLE_MS;
var MORPH_MS = 640;
var REVERT_AT = 0.62 * CYCLE_MS;
function easeOut(p) { return 1 - Math.pow(1 - p, 3); }
function apply(t) {
var inMorph = t >= MORPH_START && t < REVERT_AT;
var p = Math.min(Math.max((t - MORPH_START) / MORPH_MS, 0), 1);
var eased = easeOut(p);
var w = inMorph ? DOT_W + (MSG_W - DOT_W) * eased : DOT_W;
bubble.style.setProperty('--w', w.toFixed(1));
var done = inMorph && p >= 1;
dots.style.opacity = done ? '0' : '1';
msg.style.opacity = done ? '1' : '0';
}
apply(0);
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (reduce) { bubble.style.setProperty('--w', DOT_W); return; }
var start = null;
function loop(ts) {
if (start === null) start = ts;
var t = (ts - start) % CYCLE_MS;
apply(t);
requestAnimationFrame(loop);
}
requestAnimationFrame(loop);
})();import { useEffect, useRef } from "react";
import styles from "./TypingBubbleMorphIn.module.scss";
// 말풍선 모핑 — 점 세 개의 합산 너비 값을 말풍선 하나의 너비 값으로 보간한다.
// 계산 겹: 경과 비율 → 너비 값(px) 재계산 → CSS 커스텀 프로퍼티(--w)에 반영. 자동 재생만, 실사용자 리스너 없음.
const DOT_W = 56;
const MSG_W = 168;
const CYCLE_MS = 2000;
const MORPH_START = 0.10 * CYCLE_MS;
const MORPH_MS = 640;
const REVERT_AT = 0.62 * CYCLE_MS;
function easeOut(p: number) {
return 1 - Math.pow(1 - p, 3);
}
export default function TypingBubbleMorphIn() {
const bubbleRef = useRef<HTMLDivElement>(null);
const dotsRef = useRef<HTMLSpanElement>(null);
const msgRef = useRef<HTMLSpanElement>(null);
useEffect(() => {
const bubble = bubbleRef.current;
const dots = dotsRef.current;
const msg = msgRef.current;
if (!bubble || !dots || !msg) return;
function apply(t: number) {
const inMorph = t >= MORPH_START && t < REVERT_AT;
const p = Math.min(Math.max((t - MORPH_START) / MORPH_MS, 0), 1);
const eased = easeOut(p);
const w = inMorph ? DOT_W + (MSG_W - DOT_W) * eased : DOT_W;
bubble!.style.setProperty("--w", w.toFixed(1));
const done = inMorph && p >= 1;
dots!.style.opacity = done ? "0" : "1";
msg!.style.opacity = done ? "1" : "0";
}
apply(0);
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
if (reduce) {
bubble.style.setProperty("--w", String(DOT_W));
return;
}
let start: number | null = null;
let raf = 0;
function loop(ts: number) {
if (start === null) start = ts;
const t = (ts - start) % CYCLE_MS;
apply(t);
raf = requestAnimationFrame(loop);
}
raf = requestAnimationFrame(loop);
return () => cancelAnimationFrame(raf);
}, []);
return (
<div className={styles.stage}>
<section className={styles.panel}>
<div className={styles.row}>
<span className={styles.avatar} aria-hidden="true" />
<div ref={bubbleRef} className={styles.bubble} role="status" aria-live="polite">
<span ref={dotsRef} className={styles.dots}>
<span className={styles.dot} />
<span className={styles.dot} />
<span className={styles.dot} />
</span>
<span ref={msgRef} className={styles.msg}>메시지 도착</span>
</div>
</div>
</section>
</div>
);
}02 말풍선 모핑 — 점 세 개가 하나의 말풍선 크기로 합쳐지는 전환 — 측정 누적면적 4.594% · 움직인 프레임 13/23GODRICH 원작 · zip 에 SCSS·React 포함 · 타이핑 인디케이터 UI 9종 — 점 3개부터 그룹 채팅까지
이 데모가 속한 글
타이핑 인디케이터 UI 9종 — 점 3개부터 그룹 채팅까지타이핑 인디케이터 아홉 개 중 하나는 입력 중이던 시간이 길수록 아바타 테두리가 느리게 뛰고, 하나는 그룹 채팅에서 입력자가 바뀔 때마다 남은 시간 값으로 이름표 폭을 다시 그리고, 또 하나는 진폭 값 배열로 음성 이 글의 데모 전부 보기

