09失敗振動 — 更新が失敗した状態になると表示が左右に短く揺れる効果
更新が失敗した状態になると表示の左右位置の値が短い時間の間に何度か行き来してから0に戻り、再び引いた状態になると最初の手順がやり直されます。
使いどころネットワーク不安定状態の案内、再試行が必要な更新
attemptCountFREQshaking

<main class="stage">
<div class="prof is-demo" id="prof">
<div class="prof__phone" id="profPhone">
<div class="prof__zone">
<span class="prof__disc" id="profDisc"></span>
</div>
<div class="prof__list">
<div class="prof__row"></div>
<div class="prof__row"></div>
</div>
</div>
<span class="prof__hint" id="profHint">下に引っぱってください</span>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 계산 겹(시도 홀짝 판정·감쇠 진동 흔들림)은 JS 에 있다 — 여기는 정적 배치만.
@include stage($stage-paper);
.prof {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
gap: $sp-3;
}
.prof__phone {
position: relative;
width: 220px;
height: 168px;
overflow: hidden;
border-radius: $r-card;
background: $subject-cream;
touch-action: none;
cursor: grab;
}
.prof__zone {
position: relative;
height: 56px;
display: grid;
place-items: center;
}
.prof__disc {
width: 28px;
height: 28px;
border-radius: $r-pill;
background: rgba($subject-ink, .22);
transition: background $dur-quick $ease-out;
&--ready { background: $subject-blue-deep; }
&--fail { background: $error; }
&--ok { background: $subject-mint; }
}
.prof__list {
position: relative;
display: flex;
flex-direction: column;
gap: $sp-2;
padding: $sp-3 $sp-4;
}
.prof__row {
height: 20px;
border-radius: $r-sm;
background: $stage-paper;
}
.prof__hint {
color: $subject-ink;
font-size: 12px;
text-align: center;
}
@media (max-width: 340px) {
.prof__phone { width: 176px; height: 132px; }
.prof__zone { height: 44px; }
.prof__disc { width: 22px; height: 22px; }
.prof__list { padding: $sp-2 $sp-3; gap: $sp-1; }
.prof__row { height: 16px; }
}
@media (prefers-reduced-motion: reduce) {
.prof__disc, .prof__phone { transition: none !important; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ffffff;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.prof {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
}
.prof__phone {
position: relative;
width: 220px;
height: 168px;
overflow: hidden;
border-radius: 16px;
background: #fff7e6;
touch-action: none;
cursor: grab;
}
.prof__zone {
position: relative;
height: 56px;
display: grid;
place-items: center;
}
.prof__disc {
width: 28px;
height: 28px;
border-radius: 999px;
background: rgba(23, 20, 26, 0.22);
transition: background 220ms ease-out;
}
.prof__disc--ready {
background: #0a4fe8;
}
.prof__disc--fail {
background: #c2361a;
}
.prof__disc--ok {
background: #4cd4a6;
}
.prof__list {
position: relative;
display: flex;
flex-direction: column;
gap: 8px;
padding: 12px 16px;
}
.prof__row {
height: 20px;
border-radius: 8px;
background: #ffffff;
}
.prof__hint {
color: #17141a;
font-size: 12px;
text-align: center;
}
@media (max-width: 340px) {
.prof__phone {
width: 176px;
height: 132px;
}
.prof__zone {
height: 44px;
}
.prof__disc {
width: 22px;
height: 22px;
}
.prof__list {
padding: 8px 12px;
gap: 4px;
}
.prof__row {
height: 16px;
}
}
@media (prefers-reduced-motion: reduce) {
.prof__disc, .prof__phone {
transition: none !important;
}
}(function () {
var phone = document.getElementById('profPhone');
var disc = document.getElementById('profDisc');
var hint = document.getElementById('profHint');
var root = document.getElementById('prof');
// 계산 겹: 성공/실패는 Math.random 이 아니라 시도 횟수(attemptCount)의 홀짝으로 정해지는
// 결정적 번갈이(1회차 실패·2회차 성공…)다. 실패 시 흔들림은 감쇠 진동 AMP*e^(-t/TAU)*sin(t*FREQ) 를
// phone 의 translateX 에 얹는 시간 기반 계산이지, 매번 새 애니메이션 클래스를 재생시키는 게 아니다.
var REF = 90, MAX = 130;
var AMP = 10, TAU = 0.12, FREQ = 46;
var raw = 0, target = 0, raf1 = null;
function apply(rawV) {
var pull = Math.min(rawV, MAX) * 0.28;
disc.style.transform = 'translateY(' + pull.toFixed(1) + 'px) scale(' + (0.7 + 0.3 * Math.min(1, rawV / REF)).toFixed(2) + ')';
disc.classList.toggle('prof__disc--ready', rawV >= REF);
}
function settle() {
raw += (target - raw) * 0.3;
if (Math.abs(target - raw) < 0.3) { raw = target; }
apply(raw);
if (raw !== target) { raf1 = requestAnimationFrame(settle); } else { raf1 = null; }
}
function goTo(v) { target = v; if (raf1 === null) { raf1 = requestAnimationFrame(settle); } }
var shaking = false, shakeStart = 0;
function frame(now) {
if (shaking) {
var t = (now - shakeStart) / 1000;
var off = AMP * Math.exp(-t / TAU) * Math.sin(t * FREQ);
phone.style.transform = 'translateX(' + off.toFixed(1) + 'px)';
if (t > 0.5) { shaking = false; phone.style.transform = 'translateX(0px)'; }
}
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
var attemptCount = 0, committing = false, commitTimer = null;
function attempt() {
attemptCount += 1;
var fail = attemptCount % 2 === 1;
committing = true;
if (fail) {
hint.textContent = 'オフライン - 再試行';
disc.classList.add('prof__disc--fail');
shaking = true; shakeStart = performance.now();
commitTimer = setTimeout(function () {
disc.classList.remove('prof__disc--fail', 'prof__disc--ready');
committing = false;
raw = 0; apply(0);
hint.textContent = '下に引っぱってください';
}, 640);
} else {
hint.textContent = '更新完了';
disc.classList.add('prof__disc--ok');
commitTimer = setTimeout(function () {
disc.classList.remove('prof__disc--ok', 'prof__disc--ready');
committing = false;
raw = 0; apply(0);
hint.textContent = '下に引っぱってください';
}, 640);
}
}
var dragging = false, startY = 0, startRaw = 0;
function onDown(y) { if (committing) { return; } dragging = true; startY = y; startRaw = raw; if (raf1) { cancelAnimationFrame(raf1); raf1 = null; } }
function onMove(y) {
if (!dragging) { return; }
raw = Math.max(0, Math.min(MAX, startRaw + (y - startY)));
apply(raw);
}
function onUp() {
if (!dragging) { return; }
dragging = false;
if (raw >= REF) { attempt(); } else { goTo(0); }
}
function wireReal() {
phone.addEventListener('pointerdown', function (e) { root.classList.remove('is-demo'); stopAutoplay(); onDown(e.clientY); });
window.addEventListener('pointermove', function (e) { onMove(e.clientY); });
window.addEventListener('pointerup', onUp);
}
phone.style.touchAction = 'none';
wireReal();
apply(0);
var autoRaw = 0, autoTimer = null;
function autoTick() {
if (committing) { return; }
autoRaw += 18;
if (autoRaw >= REF) { raw = REF; apply(raw); autoRaw = 0; attempt(); return; }
raw = autoRaw; apply(raw);
}
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
function stopAutoplay() { if (autoTimer) { clearInterval(autoTimer); autoTimer = null; } if (commitTimer) { clearTimeout(commitTimer); } }
if (!reduce) { autoTimer = setInterval(autoTick, 190); }
})();import { useEffect, useRef } from "react";
import styles from "./PullRefreshOfflineRetryShake.module.scss";
export type PullRefreshOfflineRetryShakeProps = {
color?: string;
};
export default function PullRefreshOfflineRetryShake({
color = "#0a4fe8",
}: PullRefreshOfflineRetryShakeProps) {
const rootRef = useRef<HTMLDivElement | null>(null);
useEffect(() => {
const root = rootRef.current;
if (!root) return;
const phone = root.querySelector<HTMLDivElement>(`.${styles.phone}`);
const disc = root.querySelector<HTMLSpanElement>(`.${styles.disc}`);
const hint = root.querySelector<HTMLSpanElement>(`.${styles.hint}`);
if (!phone || !disc || !hint) return;
// 계산 겹: 성공/실패는 Math.random 이 아니라 시도 횟수(attemptCount)의 홀짝으로 정해지는
// 결정적 번갈이(1회차 실패·2회차 성공…)다. 실패 시 흔들림은 감쇠 진동 AMP*e^(-t/TAU)*sin(t*FREQ) 를
// phone 의 translateX 에 얹는 시간 기반 계산이지, 매번 새 애니메이션 클래스를 재생시키는 게 아니다.
const REF = 90, MAX = 130;
const AMP = 10, TAU = 0.12, FREQ = 46;
const readyClass = styles["disc--ready"];
const failClass = styles["disc--fail"];
const okClass = styles["disc--ok"];
let raw = 0, target = 0, raf1: number | null = null;
function apply(rawV: number) {
const pull = Math.min(rawV, MAX) * 0.28;
disc!.style.transform = "translateY(" + pull.toFixed(1) + "px) scale(" + (0.7 + 0.3 * Math.min(1, rawV / REF)).toFixed(2) + ")";
disc!.classList.toggle(readyClass, rawV >= REF);
}
function settle() {
raw += (target - raw) * 0.3;
if (Math.abs(target - raw) < 0.3) raw = target;
apply(raw);
raf1 = raw !== target ? requestAnimationFrame(settle) : null;
}
function goTo(v: number) { target = v; if (raf1 === null) { raf1 = requestAnimationFrame(settle); } }
let shaking = false, shakeStart = 0, rafFrame: number;
function frame(now: number) {
if (shaking) {
const t = (now - shakeStart) / 1000;
const off = AMP * Math.exp(-t / TAU) * Math.sin(t * FREQ);
phone!.style.transform = "translateX(" + off.toFixed(1) + "px)";
if (t > 0.5) { shaking = false; phone!.style.transform = "translateX(0px)"; }
}
rafFrame = requestAnimationFrame(frame);
}
rafFrame = requestAnimationFrame(frame);
let attemptCount = 0, committing = false;
let timers: number[] = [];
function clearTimers() { timers.forEach((t) => window.clearTimeout(t)); timers = []; }
function attempt() {
attemptCount += 1;
const fail = attemptCount % 2 === 1;
committing = true;
if (fail) {
hint!.textContent = "오프라인 - 다시 시도";
disc!.classList.add(failClass);
shaking = true; shakeStart = performance.now();
timers.push(window.setTimeout(() => {
disc!.classList.remove(failClass, readyClass);
committing = false;
raw = 0; apply(0);
hint!.textContent = "아래로 당기세요";
}, 640));
} else {
hint!.textContent = "새로고침 완료";
disc!.classList.add(okClass);
timers.push(window.setTimeout(() => {
disc!.classList.remove(okClass, readyClass);
committing = false;
raw = 0; apply(0);
hint!.textContent = "아래로 당기세요";
}, 640));
}
}
let dragging = false, startY = 0, startRaw = 0;
function onDown(y: number) {
if (committing) return;
dragging = true; startY = y; startRaw = raw;
if (raf1 !== null) { cancelAnimationFrame(raf1); raf1 = null; }
}
function onMove(y: number) {
if (!dragging) return;
raw = Math.max(0, Math.min(MAX, startRaw + (y - startY)));
apply(raw);
}
function onUp() {
if (!dragging) return;
dragging = false;
if (raw >= REF) { attempt(); } else { goTo(0); }
}
function onPointerDown(e: PointerEvent) { stopAutoplay(); onDown(e.clientY); }
function onPointerMove(e: PointerEvent) { onMove(e.clientY); }
phone.style.touchAction = "none";
phone.addEventListener("pointerdown", onPointerDown);
window.addEventListener("pointermove", onPointerMove);
window.addEventListener("pointerup", onUp);
apply(0);
let autoRaw = 0, autoTimer: number | null = null;
function autoTick() {
if (committing) return;
autoRaw += 18;
if (autoRaw >= REF) { raw = REF; apply(raw); autoRaw = 0; attempt(); return; }
raw = autoRaw; apply(raw);
}
function stopAutoplay() {
if (autoTimer !== null) { window.clearInterval(autoTimer); autoTimer = null; }
clearTimers();
}
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
if (!reduce) { autoTimer = window.setInterval(autoTick, 190); }
return () => {
stopAutoplay();
if (raf1 !== null) cancelAnimationFrame(raf1);
cancelAnimationFrame(rafFrame);
phone.removeEventListener("pointerdown", onPointerDown);
window.removeEventListener("pointermove", onPointerMove);
window.removeEventListener("pointerup", onUp);
};
}, []);
return (
<div ref={rootRef} className={styles.stage}>
<div className={styles.prof}>
<div className={styles.phone}>
<div className={styles.zone}>
<span className={styles.disc} style={{ "--accent": color } as any} />
</div>
<div className={styles.list}>
<div className={styles.row} />
<div className={styles.row} />
</div>
</div>
<span className={styles.hint}>아래로 당기세요</span>
</div>
</div>
);
}09 失敗振動 — 更新が失敗した状態になると表示が左右に短く揺れる効果 — 計測 累積面積 2.943% · 動いたフレーム 17/23GODRICH オリジナル · SCSS と React は zip に同梱 · 引っ張って更新 スマホ 9選 — 引いた距離で変わる更新のかたち
このデモが属する記事
引っ張って更新 スマホ 9選 — 引いた距離で変わる更新のかたち9つのうち1つは引いた距離の値が大きくなるほど実際に動く幅の値がだんだん狭くなり、1つはその距離の割合の値だけ回転の値も一緒に回り、もう1つは基準を超えた状態で指を離してはじめて確定した状態に変わります。引っ張って更新 スマホの9パターンで この記事のデモをすべて見る


