Skip to main content

React animation example

React Slider Animation: Draggable Card Carousel

A good slider follows your finger and then decides for you. Drag these cards and they track the pointer one to one; let go and the nearest card springs into the centre, taking the flick speed into account. Side cards shrink and dim so the active one is always clear, and the dots below jump to any slide.

  • 4.5 KB file
  • 5 live inputs
  • React runtime
Live, try it

How this spring card slider works

  • While dragging, the offset follows the pointer; on release, a flick faster than the threshold moves one slide.
  • The resting offset is a spring, so snapping has a slight overshoot that matches the drag speed.
  • The index is an input and "change" fires with the new slide, so it stays in sync with your state.

Add it to your React app

Install exodeui, download the file below, and paste this. The code updates as you customize. Other runtimes are in the other tabs.

import { ExodeUICanvas } from 'exodeui';

// react-image-slider.bexode goes in /public (download it below)
export function ReactImageSlider() {
  return (
    <ExodeUICanvas
      src="/react-image-slider.bexode"
      fit="Layout"
      autoPlay
      interactive
      onTrigger={(name) => {
        // fires: 'change'
      }}
      style={{ width: '100%', height: 500 }}
    />
  );
}

Inputs

InputTypeDefaultRange
indexNumber00 – 4
titlesTextAurora,Canyon,Glacier,Dunes,Reef—
accentText#f472b6hex colour
inkText#fdf2f8hex colour
bgText#100a0ehex colour

Events: change

More React animations

The same idea in other frameworks: Flutter coverflow carousel