Staggered list animations with Cascade
A cascade reveals the children of a container one after the other, when the container enters the viewport. Each package has a cascade API:
- React:
CascadeanduseCascade. - Vue:
Cascadeandv-cascade. - Astro:
Cascade. - JavaScript:
cascade().
The cascade APIs accept all the options of a reveal, and also interval.
Reveal the items one after the other
Section titled “Reveal the items one after the other”Put the items in a cascade. Select an interval to see the effect:
Your device asks for reduced motion, so the content shows with no animation.
import { Cascade } from "@awesome-reveal/react";
export function CardList({ cards }) { return ( <Cascade as="ul" className="cards" interval={0}> {cards.map((card) => ( <li key={card.id}>{card.title}</li> ))} </Cascade> );}import { Cascade } from "@awesome-reveal/react";
export function CardList({ cards }) { return ( <Cascade as="ul" className="cards" interval={80}> {cards.map((card) => ( <li key={card.id}>{card.title}</li> ))} </Cascade> );}import { Cascade } from "@awesome-reveal/react";
export function CardList({ cards }) { return ( <Cascade as="ul" className="cards" interval={160}> {cards.map((card) => ( <li key={card.id}>{card.title}</li> ))} </Cascade> );}import { Cascade } from "@awesome-reveal/react";
export function CardList({ cards }) { return ( <Cascade as="ul" className="cards" interval={320}> {cards.map((card) => ( <li key={card.id}>{card.title}</li> ))} </Cascade> );}<script setup>import { Cascade } from "@awesome-reveal/vue";
defineProps({ cards: { type: Array, required: true } });</script>
<template> <Cascade as="ul" class="cards" :interval="0"> <li v-for="card in cards" :key="card.id">{{ card.title }}</li> </Cascade></template><script setup>import { Cascade } from "@awesome-reveal/vue";
defineProps({ cards: { type: Array, required: true } });</script>
<template> <Cascade as="ul" class="cards" :interval="80"> <li v-for="card in cards" :key="card.id">{{ card.title }}</li> </Cascade></template><script setup>import { Cascade } from "@awesome-reveal/vue";
defineProps({ cards: { type: Array, required: true } });</script>
<template> <Cascade as="ul" class="cards" :interval="160"> <li v-for="card in cards" :key="card.id">{{ card.title }}</li> </Cascade></template><script setup>import { Cascade } from "@awesome-reveal/vue";
defineProps({ cards: { type: Array, required: true } });</script>
<template> <Cascade as="ul" class="cards" :interval="320"> <li v-for="card in cards" :key="card.id">{{ card.title }}</li> </Cascade></template>---import { Cascade } from "@awesome-reveal/astro";
interface Props { cards: { id: string; title: string }[];}
const { cards } = Astro.props;---
<Cascade as="ul" class="cards" interval={0}> {cards.map((card) => ( <li>{card.title}</li> ))}</Cascade>---import { Cascade } from "@awesome-reveal/astro";
interface Props { cards: { id: string; title: string }[];}
const { cards } = Astro.props;---
<Cascade as="ul" class="cards" interval={80}> {cards.map((card) => ( <li>{card.title}</li> ))}</Cascade>---import { Cascade } from "@awesome-reveal/astro";
interface Props { cards: { id: string; title: string }[];}
const { cards } = Astro.props;---
<Cascade as="ul" class="cards" interval={160}> {cards.map((card) => ( <li>{card.title}</li> ))}</Cascade>---import { Cascade } from "@awesome-reveal/astro";
interface Props { cards: { id: string; title: string }[];}
const { cards } = Astro.props;---
<Cascade as="ul" class="cards" interval={320}> {cards.map((card) => ( <li>{card.title}</li> ))}</Cascade>import { cascade } from "@awesome-reveal/core";
cascade("ul.cards", { interval: 0 });import { cascade } from "@awesome-reveal/core";
cascade("ul.cards", { interval: 80 });import { cascade } from "@awesome-reveal/core";
cascade("ul.cards", { interval: 160 });import { cascade } from "@awesome-reveal/core";
cascade("ul.cards", { interval: 320 });Only the direct element children animate. Text and deeper descendants do not animate. In React, Vue and Astro, a child with display: contents shows immediately.
Change the interval
Section titled “Change the interval”interval sets the time between the entrances of two children, in milliseconds. The default is 80. The child at position index waits delay + index * interval. So delay moves the start of the whole sequence.
A negative interval gives negative delays. Each later child then starts further into its entrance.
Reveal the words of a heading
Section titled “Reveal the words of a heading”A cascade does not split text. To reveal each word, wrap each word in an element:
import { Cascade } from "@awesome-reveal/react";
export function HeadingWords() { return ( <Cascade as="h2" className="words" interval={60}> <span>Reveal</span> <span>each</span> <span>word</span> </Cascade> );}<script setup>import { Cascade } from "@awesome-reveal/vue";</script>
<template> <Cascade as="h2" class="words" :interval="60"> <span>Reveal</span> <span>each</span> <span>word</span> </Cascade></template>---import { Cascade } from "@awesome-reveal/astro";---
<Cascade as="h2" class="words" interval={60}> <span>Reveal</span> <span>each</span> <span>word</span></Cascade>import { cascade } from "@awesome-reveal/core";
cascade("h2.words", { interval: 60 });The entrance moves the element with a transform, and an inline element cannot have a transform. So give the words display: inline-block. Select inline to see the words fade in with no movement:
Reveal each word
Reveal each word
Your device asks for reduced motion, so the content shows with no animation.
.words span { display: inline-block;}.words span { display: inline;}Reveal a long list or a tall grid
Section titled “Reveal a long list or a tall grid”A cascade schedules all its children at the same time. In a long list, or in a grid that is taller than the viewport, the last children start late or out of view. Reveal each item instead:
import { Reveal } from "@awesome-reveal/react";
export function PostList({ posts }) { return ( <ul className="posts"> {posts.map((post) => ( <Reveal as="li" key={post.id}> {post.title} </Reveal> ))} </ul> );}<script setup>import { vReveal } from "@awesome-reveal/vue";
defineProps({ posts: { type: Array, required: true } });</script>
<template> <ul class="posts"> <li v-for="post in posts" :key="post.id" v-reveal>{{ post.title }}</li> </ul></template>---import { Reveal } from "@awesome-reveal/astro";
interface Props { posts: { id: string; title: string }[];}
const { posts } = Astro.props;---
<ul class="posts"> {posts.map((post) => ( <li> <Reveal>{post.title}</Reveal> </li> ))}</ul>import { reveal } from "@awesome-reveal/core";
reveal("ul.posts > li");Also reveal each item of a virtualized list.
Things to know
Section titled “Things to know”- Add the children before the reveal. In React, Vue and Astro, the cascade reads its children when it reveals. A child that you add after the reveal shows with no animation. For JavaScript, see Targets.
- Do not put a reveal directly inside a cascade. In React and Vue, the two entrances combine on the same element. In Astro, the host of a nested
Revealhasdisplay: contents, so the cascade does not animate it, and the nestedRevealplays only its own entrance. - Wrap an Astro island in an element. An island has
display: contents, so the cascade does not animate it. - A Vue
<TransitionGroup>adds its own animations. As a direct child of a cascade, it animates the children too. - A React fragment gives one child for each element. A component that returns a fragment gives one cascade child for each element of the fragment.
- The reveal event comes from the container.
onRevealand therevealevent get the container, not each child.