Skip to content

elastixbendElastic scroll displacement

The page scrolls natively. A small spring-driven offset follows your gestures at the document edges, or trails behind scroll velocity, and springs back.

Thirty seconds to the first pull ​

bash
npm install elastixbend
ts
import { createBend } from "elastixbend";

const bend = createBend(document.querySelector("#stage")!, {
  preset: "edge",
});

// later
bend.destroy();

That is the whole setup. #stage gets a translate3d while you pull past the top or bottom of the page, and returns to rest when you stop.

Two presets, one kernel ​

Both presets share the scheduler, spring integrator, clamp, and renderer. They differ only in what drives the target.

PresetDriven byUse it when
edgeWheel and touch gestures past the document edgeYou want a rubber band at the top and bottom of a page or panel
surfaceScroll velocity, whatever produced itContent should lean and catch up, including with keyboard, scrollbar, or programmatic scroll
ts
createBend(el, { preset: "surface", lagFactor: 0.04 });

Compose with your own transform ​

The default renderer owns style.transform. If the element already has one, or if a position: fixed descendant must stay pinned, switch to the CSS variable renderer:

ts
createBend(el, { render: "cssVar" });
css
.stage {
  transform: translate3d(0, var(--bend-pull, 0px), 0);
}

Read Renderers before choosing.

The contract is public ​

The full behaviour is written down in SPEC.md, and the reasons behind the design are in DECISIONS.md. If this site and the spec ever disagree, the spec wins.

Elastic scroll displacement that never touches scroll.