StealThis .dev

Gesture Carousel

A touch-enabled carousel with momentum, snap-to-slide, and dot indicators. Swipe with velocity to advance multiple slides. No libraries.

Open in Lab
vanilla-js css
Targets: JS HTML

Code

A fully touch-enabled carousel with momentum physics. A fast swipe advances the slide even if it doesn’t cross the 25% width threshold — the velocity matters.

How it works

  1. Slides are laid out horizontally in a flex track
  2. touchstart and touchend record timestamps to compute swipe velocity
  3. If velocity exceeds 0.4px/ms the carousel advances regardless of drag distance
  4. Otherwise a 25% threshold governs whether it advances or snaps back
  5. CSS transition handles the smooth snap animation

Features

  • Dot indicator syncs with the current slide
  • Prev / next arrow buttons for mouse/keyboard users
  • Auto-advance with pause-on-hover (optional, disabled by default)
  • Infinite looping via index clamping

When to use it

  • Hero image sliders
  • Onboarding step carousels
  • Product image galleries on mobile