Embla's API · native scroll
A carousel on the browser's own scroll.
Spill has Embla Carousel's API, options, events and plugins — and nothing moves with transforms. The viewport really scrolls, so a finger, a trackpad, the keyboard and find-in-page all work as they do on any page. No dependencies, no stylesheet.
npm install @bozdev/spillThree steps
Markup you already write, the look in your CSS, one call.
2 Markup and CSS
<div class="viewport">
<div class="container">
<div class="slide">1</div>
<div class="slide">2</div>
<div class="slide">3</div>
</div>
</div>.container { display: flex; gap: 1rem; }
.slide { flex: 0 0 80%; min-width: 0; }3 Call it
import Spill from "@bozdev/spill";
const api = Spill(document.querySelector(".viewport"));
api.on("select", () => console.log(api.selectedScrollSnap()));Or no script at all: by attributes.
Why native scroll
Carousels move a track with transform and rebuild scrolling in JavaScript. That was the dependable way when they were written. Today the browser does it — and does it better where it matters most: under a finger.
| Native scroll (Spill) | Transform (Embla) | |
|---|---|---|
| A finger's momentum, iOS bounce | The browser's own | Imitated |
| Trackpad, shift + wheel | Works | Needs a plugin |
| The keyboard's focus brings a slide in | By itself | Handled separately |
| Find in page reaches a slide | Yes | No |
| Before or without JavaScript | Scrollable, readable | A clipped row |
| Snapping | CSS scroll snap | JS physics |
Small
The browser does the snapping, the momentum and a finger's drag, so there is less to ship. Minified and gzipped:
Spill, the core4.9 KB
Embla, the core (8.6.0)7.2 KB
Spill, everything (the core, attributes, three plugins)8.0 KB
Examples
Each one live, with its code.
BasicA row of slides with previous and next buttons and a dot for each snap — the API's way.AlignWhere a snap sits in the viewport — start, center or end — switched live with reInit, the selected snap kept.Slides to scrollSeveral slides in view and a snap a page: slidesToScroll "auto" groups as many as fit — two in a narrow carousel, three in a wide one.Drag freeNo snapping: thrown with a mouse or a finger, the row glides and stops where it stops.Skip snapsA strong throw passes several snaps and stops where its momentum runs out; a gentle one moves a single snap.Variable widthsSlides of different widths, each its own snap and centered when it's selected (the first and the last held to the edges) — Spill reads the sizes from your CSS.