SvelteKit scroll animations
Use @awesome-reveal/svelte to add scroll animations to a SvelteKit app. Install the package, and import it in your components.
Server rendering
Section titled “Server rendering”Reveal and Cascade render the waiting element hidden in the server HTML. The package stylesheet hides it, so the content does not flash before the script runs. SvelteKit adds the stylesheet to the server HTML, in the development server and in the production build. You do not import it.
Hydration attaches the element to the viewport observer, with no hydration mismatch. With when={true}, the server still renders the element hidden. The entrance plays after hydration.
<script> import { Cascade, Reveal } from "@awesome-reveal/svelte";</script>
<Reveal as="h1">Scroll animations in SvelteKit</Reveal><Cascade as="ul"> <li>Fast</li> <li>Small</li> <li>Accessible</li></Cascade>Components and attachments
Section titled “Components and attachments”The reveal and cascade attachments do not run on the server. The server HTML shows the element. After hydration, the attachment hides the element until it reveals, so the content shows, then hides.
- For server-rendered content, use
RevealandCascade. - Use the attachments for content that only the browser renders. Examples are content that a user action adds, and a page with
ssr = false.
Keep client-side rendering on
Section titled “Keep client-side rendering on”Do not set csr = false on a page with a reveal. The page then loads no JavaScript, so no element reveals. The stylesheet hides each waiting element for 5 seconds, then shows it with no entrance. See The 5 second hold.