03A File That Flies Into the Tray
A file icon leaves the button, follows a curved path into the tray, and on arrival the tray is pressed down and springs back with a few decaying wobbles.
Best forShowing where the received file went
FLY_MSARC_HEIGHTTRAY_BOUNCE

<main class="stage">
<div class="fl is-demo" id="flRoot">
<button class="fl__btn" id="flBtn" type="button">
<svg class="fl__icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 4v11M6.5 10.5 12 16l5.5-5.5M5 20h14"/></svg>
<span>Download</span>
</button>
<svg class="fl__file" id="flFile" viewBox="0 0 24 24" aria-hidden="true"><path d="M7 3h7l5 5v13H7zM14 3v5h5"/></svg>
<div class="fl__tray" id="flTray" role="status"><span>Received</span><b id="flCount">0</b></div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 핵심: 파일은 JS 가 베지어 곡선 위 좌표를 계산해 transform 으로 옮긴다. 도착한 순간 트레이가 스프링으로 튄다.
$fly-face: $subject-lilac;
$fly-tray: $subject-sky;
$fly-land: $subject-mint;
@include stage($stage-paper);
.fl {
position: relative;
width: 240px;
max-width: 100%;
height: 164px;
}
.fl__btn {
position: absolute;
left: 20px;
right: 20px;
top: 0;
box-sizing: border-box;
height: 56px;
display: flex;
align-items: center;
justify-content: center;
gap: $sp-3;
border: 0;
border-radius: $r-control;
background: $fly-face;
box-shadow: $shadow-press;
color: $subject-ink;
font-family: inherit;
font-size: 18px;
font-weight: 700;
line-height: 24px;
cursor: pointer;
}
.fl__btn:focus-visible { outline: 3px solid $subject-ink; outline-offset: 3px; }
.fl__icon {
width: 24px;
height: 24px;
fill: none;
stroke: currentColor;
stroke-width: 2.5;
stroke-linecap: round;
stroke-linejoin: round;
}
.fl__file {
position: absolute;
left: 0;
top: 0;
width: 28px;
height: 28px;
opacity: 0;
fill: $stage-paper;
stroke: $subject-ink;
stroke-width: 2;
stroke-linejoin: round;
pointer-events: none;
}
.fl__tray {
--h: 0;
position: absolute;
left: 0;
right: 0;
top: 92px;
box-sizing: border-box;
height: 56px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 $sp-6;
border: 3px solid $subject-ink;
border-top-width: 0;
border-radius: 0 0 $r-card $r-card;
background: color-mix(in srgb, #{$fly-tray}, #{$fly-land} calc(var(--h) * 100%));
color: $subject-ink;
font-size: 16px;
font-weight: 700;
line-height: 24px;
}
.fl__tray b { min-width: 3ch; text-align: right; font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) {
.fl__tray { transition: none; }
}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);
}
.fl {
position: relative;
width: 240px;
max-width: 100%;
height: 164px;
}
.fl__btn {
position: absolute;
left: 20px;
right: 20px;
top: 0;
box-sizing: border-box;
height: 56px;
display: flex;
align-items: center;
justify-content: center;
gap: 12px;
border: 0;
border-radius: 12px;
background: #b9a0ff;
box-shadow: 0 6px 12px rgba(23, 20, 26, 0.32);
color: #17141a;
font-family: inherit;
font-size: 18px;
font-weight: 700;
line-height: 24px;
cursor: pointer;
}
.fl__btn:focus-visible {
outline: 3px solid #17141a;
outline-offset: 3px;
}
.fl__icon {
width: 24px;
height: 24px;
fill: none;
stroke: currentColor;
stroke-width: 2.5;
stroke-linecap: round;
stroke-linejoin: round;
}
.fl__file {
position: absolute;
left: 0;
top: 0;
width: 28px;
height: 28px;
opacity: 0;
fill: #ffffff;
stroke: #17141a;
stroke-width: 2;
stroke-linejoin: round;
pointer-events: none;
}
.fl__tray {
--h: 0;
position: absolute;
left: 0;
right: 0;
top: 92px;
box-sizing: border-box;
height: 56px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 24px;
border: 3px solid #17141a;
border-top-width: 0;
border-radius: 0 0 16px 16px;
background: color-mix(in srgb, #6ec8ff, #4cd4a6 calc(var(--h) * 100%));
color: #17141a;
font-size: 16px;
font-weight: 700;
line-height: 24px;
}
.fl__tray b {
min-width: 3ch;
text-align: right;
font-variant-numeric: tabular-nums;
}
@media (prefers-reduced-motion: reduce) {
.fl__tray {
transition: none;
}
}(function () {
// 기법: 파일 아이콘은 2차 베지어 곡선 B(t) = (1-t)^2 P0 + 2(1-t)t P1 + t^2 P2 위를 날아간다.
// 제어점 P1 을 옆으로 ARC_HEIGHT 만큼 밀어 활처럼 휘게 하고, 도착하면 트레이를 TRAY_BOUNCE 만큼 눌러 스프링으로 되돌린다.
var FLY_MS = 700;
var ARC_HEIGHT = 56;
var TRAY_BOUNCE = 14;
var TRAY_K = 180;
var TRAY_DAMP = 10;
var START_MS = 200;
var CYCLE_MS = 2000;
var root = document.getElementById('flRoot');
var btn = document.getElementById('flBtn');
var file = document.getElementById('flFile');
var tray = document.getElementById('flTray');
var countEl = document.getElementById('flCount');
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var clock = 0;
var flightStart = null;
var count = 0;
var ty = 0;
var tv = 0;
var lastCycle = -1;
var t0 = null;
var lastTs = null;
function stopDemo() { root.classList.remove('is-demo'); }
function ease(t) { return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2; }
function geometry() {
var w = root.clientWidth;
var b = btn.offsetTop + btn.offsetHeight / 2;
var tr = tray.offsetTop + tray.offsetHeight / 2;
return { x: w / 2, y0: b, y2: tr };
}
function land() {
count += 1;
ty = TRAY_BOUNCE;
tv = 0;
flightStart = null;
}
function renderFile(now) {
if (flightStart === null) { file.style.opacity = '0'; return; }
var t = Math.min(1, (now - flightStart) / FLY_MS);
var e = ease(t);
var g = geometry();
var cx = g.x + 2 * ARC_HEIGHT;
var cy = (g.y0 + g.y2) / 2;
var x = (1 - e) * (1 - e) * g.x + 2 * (1 - e) * e * cx + e * e * g.x;
var y = (1 - e) * (1 - e) * g.y0 + 2 * (1 - e) * e * cy + e * e * g.y2;
var rot = 28 * Math.sin(Math.PI * e);
var sc = 1 - 0.45 * e;
file.style.opacity = t > 0.9 ? String((1 - t) * 10) : '1';
file.style.transform = 'translate(' + (x - 14).toFixed(1) + 'px,' + (y - 14).toFixed(1) + 'px) rotate(' + rot.toFixed(1) + 'deg) scale(' + sc.toFixed(3) + ')';
}
function renderTray() {
tray.style.transform = 'translateY(' + ty.toFixed(2) + 'px)';
tray.style.setProperty('--h', Math.max(0, Math.min(1, ty / TRAY_BOUNCE)).toFixed(3));
countEl.textContent = String(count);
}
function activate() {
stopDemo();
if (reduce) { count += 1; renderTray(); return; }
if (flightStart === null) flightStart = clock;
}
btn.addEventListener('click', activate);
function tick(ts) {
if (t0 === null) t0 = ts;
clock = ts - t0;
var dt = lastTs === null ? 0.016 : Math.min(0.05, (ts - lastTs) / 1000);
lastTs = ts;
if (root.classList.contains('is-demo') && clock >= START_MS) {
var cyc = Math.floor((clock - START_MS) / CYCLE_MS);
if (cyc > lastCycle) { lastCycle = cyc; count = 0; flightStart = START_MS + cyc * CYCLE_MS; }
}
if (flightStart !== null && clock - flightStart >= FLY_MS) land();
var n = Math.ceil(dt / 0.008);
var h = dt / n;
for (var i = 0; i < n; i += 1) {
tv += (-TRAY_K * ty - TRAY_DAMP * tv) * h;
ty += tv * h;
}
renderFile(clock);
renderTray();
requestAnimationFrame(tick);
}
if (reduce) {
stopDemo();
renderTray();
} else {
requestAnimationFrame(tick);
}
})();// FlyTrayButton — vanilla 판(03-dlbtn-file-fly-tray) 의 React 포트.
// 파일 아이콘은 2차 베지어 곡선 위를 날고, 도착하면 트레이가 TRAY_BOUNCE 만큼 눌렸다가 스프링으로 돌아온다.
import { useEffect, useRef } from "react";
import styles from "./FlyTrayButton.module.scss";
const FLY_MS = 700;
const ARC_HEIGHT = 56;
const TRAY_BOUNCE = 14;
const TRAY_K = 180;
const TRAY_DAMP = 10;
const START_MS = 200;
const CYCLE_MS = 2000;
function ease(t: number): number {
return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
}
export default function FlyTrayButton() {
const rootRef = useRef<HTMLDivElement | null>(null);
const btnRef = useRef<HTMLButtonElement | null>(null);
const fileRef = useRef<SVGSVGElement | null>(null);
const trayRef = useRef<HTMLDivElement | null>(null);
const countRef = useRef<HTMLElement | null>(null);
useEffect(() => {
const root = rootRef.current;
const btn = btnRef.current;
const file = fileRef.current;
const tray = trayRef.current;
const countEl = countRef.current;
if (!root || !btn || !file || !tray || !countEl) return;
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
let demo = !reduce;
let clock = 0;
let flightStart: number | null = null;
let count = 0;
let ty = 0;
let tv = 0;
let lastCycle = -1;
let t0: number | null = null;
let lastTs: number | null = null;
let raf = 0;
const land = (): void => { count += 1; ty = TRAY_BOUNCE; tv = 0; flightStart = null; };
const renderFile = (now: number): void => {
if (flightStart === null) { file.style.opacity = "0"; return; }
const t = Math.min(1, (now - flightStart) / FLY_MS);
const e = ease(t);
const gx = root.clientWidth / 2;
const y0 = btn.offsetTop + btn.offsetHeight / 2;
const y2 = tray.offsetTop + tray.offsetHeight / 2;
const cx = gx + 2 * ARC_HEIGHT;
const cy = (y0 + y2) / 2;
const x = (1 - e) * (1 - e) * gx + 2 * (1 - e) * e * cx + e * e * gx;
const y = (1 - e) * (1 - e) * y0 + 2 * (1 - e) * e * cy + e * e * y2;
const rot = 28 * Math.sin(Math.PI * e);
const sc = 1 - 0.45 * e;
file.style.opacity = t > 0.9 ? String((1 - t) * 10) : "1";
file.style.transform = `translate(${(x - 14).toFixed(1)}px,${(y - 14).toFixed(1)}px) rotate(${rot.toFixed(1)}deg) scale(${sc.toFixed(3)})`;
};
const renderTray = (): void => {
tray.style.transform = `translateY(${ty.toFixed(2)}px)`;
tray.style.setProperty("--h", Math.max(0, Math.min(1, ty / TRAY_BOUNCE)).toFixed(3));
countEl.textContent = String(count);
};
const activate = (): void => {
demo = false;
if (reduce) { count += 1; renderTray(); return; }
if (flightStart === null) flightStart = clock;
};
btn.addEventListener("click", activate);
function tick(ts: number): void {
if (t0 === null) t0 = ts;
clock = ts - t0;
const dt = lastTs === null ? 0.016 : Math.min(0.05, (ts - lastTs) / 1000);
lastTs = ts;
if (demo && clock >= START_MS) {
const cyc = Math.floor((clock - START_MS) / CYCLE_MS);
if (cyc > lastCycle) { lastCycle = cyc; count = 0; flightStart = START_MS + cyc * CYCLE_MS; }
}
if (flightStart !== null && clock - flightStart >= FLY_MS) land();
const n = Math.ceil(dt / 0.008);
const h = dt / n;
for (let i = 0; i < n; i += 1) {
tv += (-TRAY_K * ty - TRAY_DAMP * tv) * h;
ty += tv * h;
}
renderFile(clock);
renderTray();
raf = requestAnimationFrame(tick);
}
if (reduce) renderTray();
else raf = requestAnimationFrame(tick);
return () => {
cancelAnimationFrame(raf);
btn.removeEventListener("click", activate);
};
}, []);
return (
<main className={styles.stage}>
<div className={styles.fl} ref={rootRef}>
<button className={styles.fl__btn} type="button" ref={btnRef}>
<svg className={styles.fl__icon} viewBox="0 0 24 24" aria-hidden="true">
<path d="M12 4v11M6.5 10.5 12 16l5.5-5.5M5 20h14" />
</svg>
<span>내려받기</span>
</button>
<svg className={styles.fl__file} viewBox="0 0 24 24" aria-hidden="true" ref={fileRef}>
<path d="M7 3h7l5 5v13H7zM14 3v5h5" />
</svg>
<div className={styles.fl__tray} role="status" ref={trayRef}>
<span>받은 파일</span>
<b ref={countRef}>0</b>
</div>
</div>
</main>
);
}03 A File That Flies Into the Tray — Measured area 11.791% · moving frames 21/23Original by GODRICH · SCSS and React ship in the zip · CSS Download Button: 9 Demos With Springs and Arcs
The post this demo lives in
CSS Download Button: 9 Demos With Springs and ArcsA css download button that only swaps its label leaves a stiff arrow, steps in progress and no sign of where the file we See all demos in this post
If you like this effect - similar demos
Buttons09 A Chat Bubble That Arcs From the Send Button and Lands in the ThreadSend Button Animation CSS: 9 Fold-and-Fly Buttons
Buttons04 A Threshold Auto Finish That Carries the Rest and Turns Into a CheckSlide to Unlock Button: 9 Slider Scenes
Buttons02 Button that unlocks when the form is valid9 button state css patterns, loading to done