Skip to the content

Deck slider

A deck of cards a little offset from one another, seen in perspective, in place of a row.

Become a member to unlock the full effect today.

Join now

Already a member? Sign in

Documentation

  1. Copy to Webflow

    Add Geist and Geist Mono to your site's fonts (Site settings, Fonts, Google Fonts) before pasting: Webflow removes any font your site has not installed.

  2. Add custom CSS

    Give the cards one size and leave room at the sides of the deck: the leaving card swings out by a little more than its own width, so clip at the section, not at the deck. And leave the transform, the z-index, the opacity and the filter of a card to the engine, which writes the four.
  3. Add custom JS

  4. Tune it

    Custom attributes
    Select the section on the canvas and open the Settings panel. Under Custom attributes, add a pair: the name on the left, the value on the right.
    Custom attributeWhat it does
    data-deck-slider Marks the section that holds the deck. It takes no value: leave the value field empty. That section is what the engine mounts on, what carries the settings and the state, and what it looks for the deck, the buttons and the counter in. Without it on any section of the page, the embed marks the section holding each deck (data-deck-slider-deck).
    data-deck-slider-deck Marks the box that directly holds the cards. The cards lie on one another in it, so it is as large as one card, and it is what the hand drags. Without it the engine takes the parent of the first marked card, and mounts nothing when there is none. [ Required ]
    data-deck-slider-card Marks one card, a child of the deck. The first one is in front. Without it on any of them the engine takes the deck's own children as the cards. [ Optional ]
    data-deck-slider-prev Marks the button that steps back: the last card comes round to the front. Anywhere in the section, and more than one is fine. Without it the deck is stepped by the drag and the keys. [ Optional ]
    data-deck-slider-next Marks the button that steps forward: the front card goes behind the deck. Anywhere in the section. [ Optional ]
    data-deck-slider-current Marks the number of the card in front, which the engine writes on two figures. Without it there is no current number. [ Optional ]
    data-deck-slider-total Marks the total of the counter, which the engine writes as the card count. Without it there is no total. [ Optional ]
    data-deck-slider-state Written by the engine on the section: ready once mounted. While a drag runs the section also carries data-deck-slider-dragging, and the card in front data-deck-slider-active. Never written by hand; the stylesheet reads them, and so can a rule of yours. [ Optional ]
    Settings
    Every setting is a custom attribute too, added the same way and on the same section. An attribute always wins over the defaults written in the code.
    AttributeDefaultWhat it is
    data-deck-slider-turn -20 How far the deck is turned about its upright axis, in degrees. Negative shows the cards behind on the right, positive on the left.
    data-deck-slider-pitch 6 How far the deck leans back, its top away from the eye, in degrees.
    data-deck-slider-depth 0.17 The gap between two cards of the deck, along its thickness, in card widths.
    data-deck-slider-shift 0.07 How far each card stands aside from the one before, in the plane of the deck, in card widths. Negative steps to the left.
    data-deck-slider-rise 0.06 How far each card stands above the one before, in card widths. Negative steps down.
    data-deck-slider-perspective 3.4 The distance of the eye from the deck, in card widths.
    data-deck-slider-visible 4 How many cards are drawn in the deck; the rest wait behind the last one, unseen.
    data-deck-slider-dim 0.2 The share of its light a card loses for each place back, 0 to 1.
    data-deck-slider-reach 1.06 How far the leaving card swings out before it goes behind, as a multiple of what just clears the deck.
    data-deck-slider-swing 7 How far the card leans as it swings out, in degrees.
    data-deck-slider-duration 0.95 How long one step takes to settle, in seconds.
    data-deck-slider-swipe 0.2 How far a drag must go for the step to be taken on release, in card widths; a quick flick takes it whatever the distance.
    data-deck-slider-threshold 6 How far a press travels sideways, in pixels, before it becomes a drag; a shorter press is a click.

What it does

Deck slider is a scroll animation for Webflow and vanilla JavaScript, with no library. Also called stacked cards slider, card stack slider or card deck carousel.

A deck of cards a little offset from one another, seen in perspective, in place of a row. At each step the card in front leaves the top of the deck, swings out to the side on a lean, drops to the depth of the last card and comes back in behind it, while every other card moves up one place; a step back plays the same move the other way round, the last card coming round to the front. The deck goes round without end and takes as many cards as the markup holds. Three ways to step: two buttons, a drag or a swipe on the deck (the card starts out under the hand, and a release far or quick enough finishes the step), and the arrow keys. A press that does not travel stays a click, so the front card is a real link and a card behind comes to the front. A vertical swipe still scrolls the page, a counter reads the card in front, and under reduced motion a step is immediate. No library: Pointer Events, one transform per card and per frame, a clock that sleeps at rest. Pattern type stacked cards slider, card deck carousel, card stack swipe.

Updated

Questions

Paste the section, or mark your own: data-deck-slider on the section, data-deck-slider-deck on the box that directly holds the cards and data-deck-slider-card on each card, a Collection List works. The Embed lays the cards on one another in perspective and steps them; the two buttons carry data-deck-slider-prev and data-deck-slider-next.

Any number from two up, with nothing to set: the engine counts the cards of the markup. The deck goes round without end in both directions. data-deck-slider-visible says how many cards are drawn in the pile, four by default; the others wait behind the last one and fade in as they move up.

Yes. The deck sets touch-action: pan-y, so a finger moving up or down scrolls the page and only a sideways move pulls the card. The card starts out under the finger; let go past a fifth of its width, or with a quick flick, and the step is taken. A shorter drag falls back.

Yes. A press that does not travel is a click: on the front card it goes through and the link opens, on a card behind it brings that card to the front instead. A drag never opens a card, because the click that follows it is swallowed.

The deck is one Tab stop, the front card; the left and right arrows step it, Home and End go to the first and last card, and the two buttons are real buttons. Under reduced motion a step is immediate. It needs no library: one script, one spring on a requestAnimationFrame clock that sleeps at rest.