โœฆ StealThis .dev

Carousel

Content carousel with auto-play, dot indicators, previous/next arrows, touch swipe support, and a multi-card visible variant.

Open in Lab
css vanilla-js
Targets: JS HTML React Native

Expo Snack

Code

A fully-featured content carousel with two layout modes. Built with CSS transform: translateX and vanilla JS โ€” no external libraries.

Variants

  • Single-item โ€” one slide fills the viewport, with prev/next arrows, dot indicators, and auto-play
  • Multi-card โ€” three cards visible at once, scrolling one at a time

How it works

  1. .carousel-track is a flex row; the track translates on the X axis to reveal slides
  2. goTo(index) calculates the correct translateX offset and applies a CSS transition
  3. Auto-play uses setInterval; hovering the carousel pauses it and restores on mouseleave
  4. Touch swipe is detected via touchstart/touchend delta โ€” a swipe of >50px triggers prev/next
  5. Dots sync with the current index; clicking a dot jumps directly to that slide

Keyboard

  • Left/Right arrow keys navigate slides when the carousel has focus
  • Auto-play pauses on focus-within for accessibility