React and Vue scroll animations in Astro
To add scroll animations inside a React or Vue island of an Astro site, install @awesome-reveal/react or @awesome-reveal/vue. These packages need two steps in Astro. For the markup of .astro files, use @awesome-reveal/astro.
Import the stylesheet
Section titled “Import the stylesheet”In the island, use the package as in any React or Vue app. In the page or in the layout, import the reveal.css of the package. Then hydrate the island with client:load:
import { Cascade } from "@awesome-reveal/react";
export default function FeatureList() { return ( <Cascade as="ul"> <li>Small</li> <li>Native</li> <li>Accessible</li> </Cascade> );}---import "@awesome-reveal/react/reveal.css";import FeatureList from "../components/FeatureList.jsx";---
<FeatureList client:load /><script setup>import { Cascade } from "@awesome-reveal/vue";</script>
<template> <Cascade as="ul"> <li>Small</li> <li>Native</li> <li>Accessible</li> </Cascade></template>---import "@awesome-reveal/vue/reveal.css";import FeatureList from "../components/FeatureList.vue";---
<FeatureList client:load />The stylesheet hides the waiting elements in the server HTML. The package imports it only in the browser build. Astro gets the CSS of a page from the server build, so it does not add the stylesheet of an island. Without the import, the content shows before the reveal.
Hydrate the island with client:load
Section titled “Hydrate the island with client:load”The server HTML hides each waiting element until the island hydrates, for at most 5 seconds. See The 5 second hold.
client:visible hydrates the island when it enters the viewport. That is often after 5 seconds, so the content shows, then hides. Use client:load.
Islands in a Cascade
Section titled “Islands in a Cascade”The Cascade of @awesome-reveal/astro does not animate an island that is its direct child. An island has display: contents. Wrap each island in an element:
---import { Cascade } from "@awesome-reveal/astro";import Card from "../components/Card.jsx";---
<Cascade as="ul"> <li> <Card client:load title="Fast" /> </li> <li> <Card client:load title="Small" /> </li></Cascade>