04고무줄 한계 — 최대 거리 값을 넘어서면 늘어나는 폭이 급격히 줄어드는 당김
당긴 거리 값이 정해진 최대 값에 가까워질수록 같은 힘에도 늘어나는 폭 값이 급격히 줄어들고, 손을 뗀 상태가 되면 거리 값이 원래 위치로 튕겨 돌아옵니다.
쓰임짧은 리스트 새로고침, 과도한 당김 방지 영역
LINEARMAX_DdisplayedOf

<main class="stage">
<div class="prrbo is-demo" id="prrbo">
<div class="prrbo__panel">
<div class="prrbo__track" id="prrboTrack">
<span class="prrbo__cap"></span>
<span class="prrbo__marker" id="prrboMarker"></span>
</div>
<div class="prrbo__phone" id="prrboPhone">
<div class="prrbo__list" id="prrboList">
<div class="prrbo__row"></div>
<div class="prrbo__row"></div>
</div>
</div>
</div>
<span class="prrbo__hint" id="prrboHint">아래로 당기세요</span>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 계산 겹(지수 감쇠 displayedOf())은 JS 에 있다 — 여기는 정적 배치만.
@include stage($stage-orange);
.prrbo {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
gap: $sp-3;
}
.prrbo__panel {
display: flex;
align-items: flex-end;
gap: $sp-4;
padding: $sp-4;
border-radius: $r-card;
background: $stage-paper;
}
.prrbo__track {
position: relative;
width: 20px;
height: 92px;
border-radius: $r-xs;
background: $subject-cream;
}
.prrbo__cap {
position: absolute;
left: -4px;
right: -4px;
bottom: 77px;
height: 2px;
background: $subject-orange-deep;
}
.prrbo__marker {
position: absolute;
left: 2px;
right: 2px;
bottom: 2px;
height: 12px;
border-radius: $r-xs;
background: $subject-blue-deep;
}
.prrbo__phone {
position: relative;
width: 156px;
height: 108px;
overflow: hidden;
border-radius: $r-sm;
background: $subject-cream;
touch-action: none;
cursor: grab;
}
.prrbo__list {
position: relative;
display: flex;
flex-direction: column;
gap: $sp-2;
padding: $sp-3;
}
.prrbo__row {
height: 18px;
border-radius: $r-xs;
background: $stage-paper;
}
.prrbo__hint {
color: $subject-ink;
font-size: 12px;
text-align: center;
}
@media (max-width: 340px) {
.prrbo__panel { padding: $sp-3; gap: $sp-2; }
.prrbo__track { height: 72px; }
.prrbo__cap { bottom: 60px; }
.prrbo__phone { width: 128px; height: 88px; }
}
@media (prefers-reduced-motion: reduce) {
.prrbo__marker, .prrbo__list { 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: #ff4d1f;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.prrbo {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
}
.prrbo__panel {
display: flex;
align-items: flex-end;
gap: 16px;
padding: 16px;
border-radius: 16px;
background: #ffffff;
}
.prrbo__track {
position: relative;
width: 20px;
height: 92px;
border-radius: 4px;
background: #fff7e6;
}
.prrbo__cap {
position: absolute;
left: -4px;
right: -4px;
bottom: 77px;
height: 2px;
background: #c93000;
}
.prrbo__marker {
position: absolute;
left: 2px;
right: 2px;
bottom: 2px;
height: 12px;
border-radius: 4px;
background: #0a4fe8;
}
.prrbo__phone {
position: relative;
width: 156px;
height: 108px;
overflow: hidden;
border-radius: 8px;
background: #fff7e6;
touch-action: none;
cursor: grab;
}
.prrbo__list {
position: relative;
display: flex;
flex-direction: column;
gap: 8px;
padding: 12px;
}
.prrbo__row {
height: 18px;
border-radius: 4px;
background: #ffffff;
}
.prrbo__hint {
color: #17141a;
font-size: 12px;
text-align: center;
}
@media (max-width: 340px) {
.prrbo__panel {
padding: 12px;
gap: 8px;
}
.prrbo__track {
height: 72px;
}
.prrbo__cap {
bottom: 60px;
}
.prrbo__phone {
width: 128px;
height: 88px;
}
}
@media (prefers-reduced-motion: reduce) {
.prrbo__marker, .prrbo__list {
transition: none !important;
}
}(function () {
var phone = document.getElementById('prrboPhone');
var marker = document.getElementById('prrboMarker');
var list = document.getElementById('prrboList');
var hint = document.getElementById('prrboHint');
var root = document.getElementById('prrbo');
// 계산 겹: LINEAR(70px) 까지는 raw 에 0.9 배로 거의 그대로 따라가다가, 그 뒤로는 MAX_D(120px) 에
// 점근하는 지수 감쇠(1-e^-x/K)로 늘어나는 폭이 급격히 줄어든다 — 같은 힘이라도 한계 근처에선 거의 안 늘어난다.
var LINEAR = 70, MAX_D = 120, K = 42, RAW_MAX = 260;
var TRACK_H = 92, SCALE = TRACK_H / 150;
function displayedOf(raw) {
if (raw <= LINEAR) { return raw * 0.9; }
var base = LINEAR * 0.9;
var excess = raw - LINEAR;
return base + (MAX_D - base) * (1 - Math.exp(-excess / K));
}
function apply(raw) {
var displayed = displayedOf(raw);
marker.style.transform = 'translateY(' + (-(displayed * SCALE)).toFixed(1) + 'px)';
list.style.transform = 'translateY(' + (displayed * 0.55).toFixed(1) + 'px)';
var pctOfCap = Math.round((displayed / MAX_D) * 100);
hint.textContent = raw > 4 ? ('밀림 ' + Math.round(displayed) + 'px · 한계의 ' + pctOfCap + '%') : '아래로 당기세요';
}
var raw = 0, target = 0, raf = null;
function settle() {
raw += (target - raw) * 0.3;
if (Math.abs(target - raw) < 0.3) { raw = target; }
apply(raw);
if (raw !== target) { raf = requestAnimationFrame(settle); } else { raf = null; }
}
function goTo(v) { target = v; if (raf === null) { raf = requestAnimationFrame(settle); } }
var dragging = false, startY = 0, startRaw = 0;
function onDown(y) { dragging = true; startY = y; startRaw = raw; if (raf) { cancelAnimationFrame(raf); raf = null; } }
function onMove(y) {
if (!dragging) { return; }
raw = Math.max(0, Math.min(RAW_MAX, startRaw + (y - startY)));
apply(raw);
}
function onUp() { if (!dragging) { return; } dragging = false; 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);
// 자동 루프: raw 를 RAW_MAX 까지 크게 밀어 넣어 한계선에 점근만 하고 못 넘는 모습을 보인다.
var autoRaw = 0, autoTimer = null, autoDir = 1;
function autoTick() {
autoRaw += autoDir * 55;
if (autoRaw >= RAW_MAX) { autoRaw = RAW_MAX; autoDir = -1; goTo(0); return; }
if (autoRaw <= 0 && autoDir < 0) { autoRaw = 0; autoDir = 1; }
if (autoDir > 0) { raw = autoRaw; apply(raw); }
}
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
function stopAutoplay() { if (autoTimer) { clearInterval(autoTimer); autoTimer = null; } }
if (!reduce) { autoTimer = setInterval(autoTick, 170); }
})();import { useEffect, useRef } from "react";
import styles from "./PullRefreshRubberBandOverscroll.module.scss";
export type PullRefreshRubberBandOverscrollProps = {
color?: string;
};
export default function PullRefreshRubberBandOverscroll({
color = "#0a4fe8",
}: PullRefreshRubberBandOverscrollProps) {
const rootRef = useRef<HTMLDivElement | null>(null);
useEffect(() => {
const root = rootRef.current;
if (!root) return;
const phone = root.querySelector<HTMLDivElement>(`.${styles.phone}`);
const marker = root.querySelector<HTMLSpanElement>(`.${styles.marker}`);
const list = root.querySelector<HTMLDivElement>(`.${styles.list}`);
const hint = root.querySelector<HTMLSpanElement>(`.${styles.hint}`);
if (!phone || !marker || !list || !hint) return;
// 계산 겹: LINEAR(70px) 까지는 raw 에 0.9 배로 거의 그대로 따라가다가, 그 뒤로는 MAX_D(120px) 에
// 점근하는 지수 감쇠(1-e^-x/K)로 늘어나는 폭이 급격히 줄어든다 — 같은 힘이라도 한계 근처에선 거의 안 늘어난다.
const LINEAR = 70, MAX_D = 120, K = 42, RAW_MAX = 260;
const TRACK_H = 92, SCALE = TRACK_H / 150;
function displayedOf(raw: number) {
if (raw <= LINEAR) return raw * 0.9;
const base = LINEAR * 0.9;
const excess = raw - LINEAR;
return base + (MAX_D - base) * (1 - Math.exp(-excess / K));
}
function apply(raw: number) {
const displayed = displayedOf(raw);
marker!.style.transform = "translateY(" + (-(displayed * SCALE)).toFixed(1) + "px)";
list!.style.transform = "translateY(" + (displayed * 0.55).toFixed(1) + "px)";
const pctOfCap = Math.round((displayed / MAX_D) * 100);
hint!.textContent = raw > 4 ? ("밀림 " + Math.round(displayed) + "px · 한계의 " + pctOfCap + "%") : "아래로 당기세요";
}
let raw = 0, target = 0, raf: number | null = null;
function settle() {
raw += (target - raw) * 0.3;
if (Math.abs(target - raw) < 0.3) raw = target;
apply(raw);
raf = raw !== target ? requestAnimationFrame(settle) : null;
}
function goTo(v: number) { target = v; if (raf === null) { raf = requestAnimationFrame(settle); } }
let dragging = false, startY = 0, startRaw = 0;
function onDown(y: number) {
dragging = true; startY = y; startRaw = raw;
if (raf !== null) { cancelAnimationFrame(raf); raf = null; }
}
function onMove(y: number) {
if (!dragging) return;
raw = Math.max(0, Math.min(RAW_MAX, startRaw + (y - startY)));
apply(raw);
}
function onUp() { if (!dragging) return; dragging = false; 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);
// 자동 루프: raw 를 RAW_MAX 까지 크게 밀어 넣어 한계선에 점근만 하고 못 넘는 모습을 보인다.
let autoRaw = 0, autoTimer: number | null = null, autoDir = 1;
function autoTick() {
autoRaw += autoDir * 55;
if (autoRaw >= RAW_MAX) { autoRaw = RAW_MAX; autoDir = -1; goTo(0); return; }
if (autoRaw <= 0 && autoDir < 0) { autoRaw = 0; autoDir = 1; }
if (autoDir > 0) { raw = autoRaw; apply(raw); }
}
function stopAutoplay() { if (autoTimer !== null) { window.clearInterval(autoTimer); autoTimer = null; } }
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
if (!reduce) { autoTimer = window.setInterval(autoTick, 170); }
return () => {
stopAutoplay();
if (raf !== null) cancelAnimationFrame(raf);
phone.removeEventListener("pointerdown", onPointerDown);
window.removeEventListener("pointermove", onPointerMove);
window.removeEventListener("pointerup", onUp);
};
}, []);
return (
<div ref={rootRef} className={styles.stage}>
<div className={styles.prrbo}>
<div className={styles.panel}>
<div className={styles.track}>
<span className={styles.cap} style={{ "--accent": color } as any} />
<span className={styles.marker} />
</div>
<div className={styles.phone}>
<div className={styles.list}>
<div className={styles.row} />
<div className={styles.row} />
</div>
</div>
</div>
<span className={styles.hint}>아래로 당기세요</span>
</div>
</div>
);
}04 고무줄 한계 — 최대 거리 값을 넘어서면 늘어나는 폭이 급격히 줄어드는 당김 — 측정 누적면적 9.799% · 움직인 프레임 15/23GODRICH 원작 · zip 에 SCSS·React 포함 · 당겨서 새로고침 9종 — 당긴 거리 값이 새로고침을 만드는 방식
이 데모가 속한 글
당겨서 새로고침 9종 — 당긴 거리 값이 새로고침을 만드는 방식당겨서 새로고침은 리스트를 위로 당겼다가 놓는 손짓에 거리 값을 계산해 새로고침을 트리거하는 동작인데, 아홉 개 중 하나는 당긴 거리 값이 커질수록 실제로 밀리는 폭 값이 점점 좁아지고, 하나는 그 거리의 비율 값만 이 글의 데모 전부 보기


