Components Controls & Input VelocityCurl

VelocityCurl

Scroll-velocity skew wrapper β€” content bends with fling speed, settles with fast-attack/slow-release smoothing.

Live demo

01

Playground β€” fling this page (or the list) and watch the stack bend

Card 1

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 2

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 3

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 4

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 5

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 6

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 7

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 8

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 9

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 10

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 11

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 12

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 13

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 14

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 15

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 16

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 17

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 18

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 19

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 20

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 21

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 22

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 23

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Card 24

Fling the page β€” this whole feed bends with your scroll velocity, then exhales back to straight.

Reduced-motion users: the sampler never attaches β€” this stack stays perfectly still for you (that’s the point).

Implementation

02
VelocityCurl.svelte
<script lang="ts">
  import VelocityCurl from '$lib/components/VelocityCurl.svelte';
</script>
​
<VelocityCurl amount={2.5} mode="skew">
  <article>Long scrollable content that flexes as you fling it.</article>
</VelocityCurl>

VelocityCurl attaches one passive scroll listener and, while scrolling, runs a single rAF loop: velocity = |Ξ”scrollY|/Ξ”t with Ξ”t clamped (1/240s..0.1s) so background-tab wakeups cannot spike. The signal is smoothed asymmetrically β€” 25ms attack so a fling registers instantly, 175ms release so the settle breathes β€” and written to a single CSS custom property that drives a GPU-composited skewY (or rotateX) transform. At rest the loop cancels itself; with prefers-reduced-motion the listener is never even attached.

Logic explainer

03

What Does It Do? (Plain English)

Wrap any content and it gently bends with scroll speed β€” fling the page and the content skews a degree or two, then settles back smoothly, like paper reacting to air. It makes scrolling feel physical without touching layout.

How It Works (Pseudo-Code)

on scroll event: wake the rAF loop (passive listener, zero cost at rest)
each frame:
    velocity = |Ξ”scrollY| / Ξ”t   (Ξ”t clamped 1/240s..0.1s)
    activity β†’ attack-fast / release-slow exponential smoothing
    write --velocity-curl (0..amount) to the wrapper
when activity < Ξ΅: write 0, cancel rAF, go idle
reduced motion: never start; the wrapper applies no transform at all

The Attack/Release Curve

A raw velocity signal is unusable β€” trackpads emit tiny spikes that read as jitter. The sampler uses asymmetric time constants: attack Ο„β‰ˆ25ms (a real fling registers instantly), release Ο„β‰ˆ175ms (the settle is a slow exhale). The visible transform is a single CSS custom property driving skewY (or rotateX with perspective), so the browser composites it on the GPU.

State Flow Diagram

resting ──scroll event──▢ sampling (rAF, writes --velocity-curl)
   β–²                          β”‚
   └── activity < epsilon β—€β”€β”€β”€β”˜
reduced motion: resting forever (no listener, no transform)

Props Reference

Prop Type Default Description
amount number 2 Maximum bend in degrees
mode 'skew' | 'rotateX' 'skew' Bend style
attack number 0.025 Attack time constant (s)
release number 0.175 Release time constant (s)
disabledBelow number 0.02 Activity epsilon for idling
class string '' Extra classes

Edge Cases

  • Background tabs: dt clamping means a minute-long sleep can't spike the value on wake.
  • Reduced motion: the scroll listener is never even attached.
  • Nested scrollers: the sampler reads window.scrollY β€” for a nested scroller, wrap that scroller's content and scroll its container (or fork the sampler to take a ref).
  • Compositor cost: one will-change: transform while active; released when idle.

Dependencies

Zero. rAF + one passive scroll listener + a CSS custom property.

File Structure

src/lib/components/VelocityCurl.svelte   β€” component (sampler exported from module script)
src/lib/components/VelocityCurl.md       β€” this doc
src/lib/components/VelocityCurl.test.ts  β€” 6 sampler unit tests
src/routes/velocitycurl/+page.svelte     β€” demo (skew/rotateX playground)