Skip to content

Nuxt and Vue SSR scroll animations

Use @awesome-reveal/vue to add scroll animations to a Nuxt app or to your own Vue SSR setup. Install the package, and import it in your components. Server rendering needs no setup. The Nuxt development server needs one line of config.

Reveal, Cascade, v-reveal and v-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. Your bundler adds the stylesheet to the page.

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.

Import the components and the directives in your components, as in any Vue app:

app/pages/index.vue
<script setup>
import { Cascade, Reveal } from "@awesome-reveal/vue";
</script>
<template>
<Reveal as="h1">Scroll animations in Nuxt</Reveal>
<Cascade as="ul">
<li>Fast</li>
<li>Small</li>
<li>Accessible</li>
</Cascade>
</template>

Register the directives for all components

Section titled “Register the directives for all components”

To use v-reveal and v-cascade with no import, register them in a Nuxt plugin. The GlobalDirectives declaration lets TypeScript check the values of the directives:

app/plugins/awesome-reveal.ts
import { vCascade, vReveal } from "@awesome-reveal/vue";
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.directive("reveal", vReveal);
nuxtApp.vueApp.directive("cascade", vCascade);
});
declare module "vue" {
interface GlobalDirectives {
vReveal: typeof vReveal;
vCascade: typeof vCascade;
}
}

In a Vue app without Nuxt, call app.directive("reveal", vReveal) on your app.

The production build of Nuxt adds the package stylesheet to the server HTML. The development server adds it only after the page loads, so the content can show for a moment before it hides. To get the same result as in production, add the stylesheet to the css option:

nuxt.config.ts
export default defineNuxtConfig({
css: ["@awesome-reveal/vue/reveal.css"],
});

The production build adds the stylesheet one time.

The server HTML hides each waiting element until hydration attaches it, for at most 5 seconds. See The 5 second hold.

Lazy hydration often attaches the element after 5 seconds. Examples are hydrateOnVisible() in Vue and the hydrate-on-visible prop of a Nuxt lazy component. Then the content shows, and hides again when the user scrolls to it. Do not use lazy hydration for components with a reveal.