Skip to the content

Flick cards

A pile of cards seen from the front, the top one straight, the ones under it leaning a little each its own way.

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 round the pile: a card sent flies a little more than its own size away before it turns back, so clip at the section, not at the pile. 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-flick-cards Marks the section that holds the pile. 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 pile, the buttons, the counter, the fields and the dots in. Without it on any section of the page, the embed marks the section holding each pile (data-flick-cards-pile).
    data-flick-cards-pile 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 presses. Without it the engine takes the parent of the first marked card, and mounts nothing when there is none. [ Required ]
    data-flick-cards-card Marks one card, a child of the pile. The first one is on top. Without it on any of them the engine takes the pile's own children as the cards. [ Optional ]
    data-flick-cards-prev Marks the button that brings the last card sent back on top. Anywhere in the section, and more than one is fine. Without it the keyboard still does it, Shift with an arrow or Backspace. [ Optional ]
    data-flick-cards-next Marks the button that sends the top card, to the right. Anywhere in the section. [ Optional ]
    data-flick-cards-current Marks the number of the card on top, which the engine writes on two figures. Without it there is no current number. [ Optional ]
    data-flick-cards-total Marks the total of the counter, which the engine writes as the card count. Without it there is no total. [ Optional ]
    data-flick-cards-field Marks a line of text the engine fills from the card on top, anywhere in the section. Its value names the field: an element with data-flick-cards-field="title" takes the words the top card carries in data-flick-cards-field-title, and comes in over the swap setting. A card that carries no such attribute leaves the line as it is. Without it nothing outside the pile changes but the counter. [ Optional ]
    data-flick-cards-tone On a card: its colour, any CSS colour. The engine hands the colour of the card on top to the section as the custom property --flick-cards-tone, which the stylesheet fades from one card to the next and paints the glow with. Without it the property keeps its last value. [ Optional ]
    data-flick-cards-dot Marks one entry of a list of the cards, anywhere in the section: the first one stands for the first card, and so on. The engine marks the entry of the card on top with data-flick-cards-active and aria-current, and a click on an entry puts its card on top. Without it the pile has no list. [ Optional ]
    data-flick-cards-glow Marks the box of the preview that the stylesheet paints with a soft light in the colour of the card on top. The engine does not read it. Without it there is no glow. [ Optional ]
    data-flick-cards-state Written by the engine on the section: ready once mounted, with data-flick-cards-ways beside it, both or x. While a drag runs the section also carries data-flick-cards-dragging, and the card on top data-flick-cards-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-flick-cards-axis both The ways a card can be sent. both: any direction, and the pile keeps every move of a finger. x: left and right only, the card stays level, and a vertical swipe scrolls the page. Options: both or x.
    data-flick-cards-spread 5 How far a card under the top one leans, in degrees. Each card keeps its own share of it, one to the left, the next to the right.
    data-flick-cards-rise 0.05 How far each card stands above the one before, in card widths. Negative steps down.
    data-flick-cards-shrink 0.04 The share of its size a card loses for each place back, 0 to 1.
    data-flick-cards-dim 0.14 The share of its light a card loses for each place back, 0 to 1.
    data-flick-cards-visible 4 How many cards are drawn in the pile; the rest wait under the last one, unseen.
    data-flick-cards-tilt 16 How far a card turns when the hand has carried it one card width aside, held by its edge, in degrees. Held nearer its middle it turns less, held by its foot the other way.
    data-flick-cards-distance 0.5 How far a card must be carried for it to be sent on release whatever the speed, in card widths.
    data-flick-cards-flick 1.2 The speed of the hand at release that sends the card before distance is reached, in card widths per second.
    data-flick-cards-carry 1 The share of the hand's speed the card keeps as it leaves, and as it falls back.
    data-flick-cards-duration 0.7 How long a card takes to settle on its place, in seconds.
    data-flick-cards-bounce 0.25 How much the spring gives, 0 to 1: the share of overshoot of a card reaching its place.
    data-flick-cards-threshold 6 How far a press travels, in pixels, before it becomes a drag; a shorter press is a click.
    data-flick-cards-swap 0.45 How long a line of text marked as a field takes to come in when another card comes on top, in seconds.

What it does

Flick cards is a scroll animation for Webflow and vanilla JavaScript, with no library. Also called flick cards slider, swipe cards stack or swipeable card stack.

A pile of cards seen from the front, the top one straight, the ones under it leaning a little each its own way. The hand takes the top card and it follows, turning about the point it is held by; let go with a quick flick, in any direction, and the card leaves that way with the speed and the turn the hand gave it, while the next card straightens and moves up. Once it overlaps nothing the card changes order, and a spring brings it back in under the pile, so the pile goes round without end and takes as many cards as the markup holds. A flick too short or too slow sends nothing: the card falls back on the same spring, with a little give. The arrow keys send the top card their own way, two buttons send it and bring the last one back, a press that does not travel stays a click so a card may be a link, a counter reads the card on top, and under reduced motion the next card is simply there. The page follows the pile: a line of text marked as a field takes the words of the card on top, the section takes its colour, and a list of the cards marks its entry and puts a card on top at a click. The event says which card left and on which side, for a pile that sorts as well as it shows. No library: Pointer Events, one spring per card, a clock that sleeps at rest. Pattern type flick cards slider, swipe cards, card stack you throw.

Updated

Questions

Paste the section, or mark your own: data-flick-cards on the section, data-flick-cards-pile on the box that directly holds the cards and data-flick-cards-card on each card, a Collection List works. The Embed lays the cards in a pile and lets the hand send the top one; the two buttons carry data-flick-cards-prev and data-flick-cards-next.

The release. A card goes when the hand was moving away faster than flick, 1.2 card widths per second by default, or when it was carried further than distance, half a card width. It then leaves the way the hand went, at the hand's speed. Anything shorter or slower falls back on a spring, and so does a card thrown back toward the pile.

It flies until it overlaps no other card, goes to the bottom of the pile and slides back in under it, so the pile goes round without end. Any number of cards from two up works, with nothing to set: the engine counts the cards of the markup. data-flick-cards-visible says how many are drawn, four by default.

Yes. The flickcards:change event carries detail.sent, the card that left, and detail.side, the way it went: left, right, up or down. Listen to it on the section and keep or drop the card from there; data-flick-cards-axis="x" keeps the cards to left and right only.

A finger flicks a card as a mouse does. With axis at both the pile keeps every move of the finger; set it to x and a vertical swipe scrolls the page again. The pile is one Tab stop: each arrow key sends the top card its own way, and Shift with an arrow or Backspace brings the last one back. Under reduced motion the next card is simply there. It needs no library: one script, one spring per card.