v2.7 · scrollSnap · horizontal

Horizontal snap carousel

CSS scroll-snap is excellent until you need to know which slide you landed on, or want easing other than the browser default. scrollSnap keeps the drag feel but adds a threshold you control, custom easing, and an onSnap callback — which is what the dot indicators in this example are wired to, rather than polling scroll position.

The code

Drag or swipe between cards — scrollSnap detects when you pass the threshold and smoothly animates to the nearest card with custom easing. Dot indicators update via onSnap callback.

Hero.tsx
import { scrollSnap } from 'svg-scroll-draw/snap';

// Horizontal card carousel with custom easing
const snap = scrollSnap('.card', {
  direction:  'horizontal',
  duration:   400,
  easing:     'ease-out',
  threshold:  0.3,       // snap if user dragged >30% of card width
  onSnap:     (index) => setActiveCard(index),
});

// Vertical section snapping (fullscreen sections)
scrollSnap('.section', {
  duration: 600,
  easing:   'ease-in-out',
  onSnap:   (i) => history.replaceState(null, '', `#section-${i}`),
});

// Programmatic control
snap.snapTo(2);             // jump to index 2 with animation
snap.getCurrentIndex();     // → currently snapped index
snap.destroy();

Live — scroll it

📌
01 / 4
Scroll Pin
← Drag or swipe to snap →
02 / 4
Scroll Snap
← Drag or swipe to snap →
🎯
03 / 4
Callbacks
← Drag or swipe to snap →
🌊
04 / 4
Lenis
← Drag or swipe to snap →

Install

terminal
npm i svg-scroll-draw

MIT licensed, zero runtime dependencies. Every API is a separate entry point, so you only ship what you import. Full API reference →