Skip to content

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.

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:

src/components/FeatureList.jsx
import { Cascade } from "@awesome-reveal/react";
export default function FeatureList() {
return (
<Cascade as="ul">
<li>Small</li>
<li>Native</li>
<li>Accessible</li>
</Cascade>
);
}
src/pages/index.astro
---
import "@awesome-reveal/react/reveal.css";
import FeatureList from "../components/FeatureList.jsx";
---
<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.

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.

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>