framework / nuxtNuxt 3 & 4 · SSR · static

Nuxt scroll animations. One line in nuxt.config.

svg-scroll-draw/nuxt is a Nuxt module: add it to modules and every component and composable is auto-imported, the way Nuxt's own are. It still re-exports the full Vue surface, so you can import by hand instead. Either way it is SSR-safe — the engine only starts after mount, so server rendering never touches the DOM.

API reference →24 live examples →
nuxt entry
16.1 KB
Every API
11.9 KB
GSAP stack
47.5 KB
Version
2.31.0
01Module, composable or component

Quick start

Import from svg-scroll-draw/nuxt — every sample below is written against the wrappers this package actually exports.

Or start from a running project: the Nuxt starter on StackBlitz ↗ opens in the browser with nothing to install: a line drawing, words on scroll, a fade-in and a counter.

  1. sample 01nuxt.config.ts

    Add the module

    nuxt.config.ts3 lines
    export default defineNuxtConfig({
      modules: ['svg-scroll-draw/nuxt'],
    });
  2. sample 02pages/index.vue

    Use the components and composables — no imports

    pages/index.vue20 lines
    <script setup>
    // Auto-imported by the module.
    const card = useScrollAnimate({ props: { opacity: [0, 1] }, once: true });
    </script>
    
    <template>
      <main>
        <ScrollDraw :speed="1.2" once>
          <svg viewBox="0 0 200 100">
            <path d="M10 50 Q 100 10 190 50" stroke="#111" fill="none" />
          </svg>
        </ScrollDraw>
    
        <ScrollText tag="h2" :options="{ split: 'words', stagger: 0.05 }">
          Every API, one package.
        </ScrollText>
    
        <div ref="card">…</div>
      </main>
    </template>
  3. sample 03components/Hero.vue

    Or import by hand

    components/Hero.vue13 lines
    <script setup>
    import { useScrollDraw } from 'svg-scroll-draw/nuxt';
    
    const container = useScrollDraw({ easing: 'ease-out', speed: 1.2 });
    </script>
    
    <template>
      <div ref="container">
        <svg viewBox="0 0 200 100">
          <path d="M10 50 Q 100 10 190 50" stroke="#111" fill="none" />
        </svg>
      </div>
    </template>
!worth knowing

The Nuxt entry re-exports the Vue wrappers rather than reimplementing them, so anything true of the Vue API is true here — including that the composables return refs you bind, rather than taking a ref as an argument.

02module

One line in nuxt.config

Since 2.27.0 svg-scroll-draw/nuxt is a Nuxt module. Add it to modules and Nuxt auto-imports six components (<ScrollDraw>, <ScrollAnimate>, <ScrollCounter>, <ScrollVideo>, <ScrollFrames>, <ScrollText>) and six composables (useScrollDraw to useScrollText), the way it auto-imports its own. Each points at svg-scroll-draw/vue, so they are the Vue wrappers, prop for prop.

Its options go under svgScrollDraw in the config, or inline as ['svg-scroll-draw/nuxt', { … }], which wins. prefix goes before every component name ('Ink' gives <InkScrollDraw>), and components or composables set to false leaves that half out.

It is a plain function module that adds entries through two of Nuxt's hooks, components:extend and imports:extend, so the package still has no dependencies: not nuxt, not @nuxt/kit. CI builds a Nuxt 4 and a Nuxt 3 app with it on every push, checks the server HTML and scrolls it in Chromium.

nuxt.config.ts5 lines
export default defineNuxtConfig({
  modules: ['svg-scroll-draw/nuxt'],
  // Optional; these are the defaults.
  svgScrollDraw: { prefix: '', components: true, composables: true },
});
03plugin

Without the module: one plugin, six global components

createScrollDrawPlugin() returns a plain Vue plugin. Its install makes six app.component() calls, for ScrollDraw, ScrollAnimate, ScrollCounter, ScrollVideo, ScrollFrames and ScrollText, and does nothing else: no directive, no provide, no composables. The browser suite installs it on a real Vue app and renders <ScrollDraw> and <ScrollAnimate> by name, with no local components option.

The plugin file needs no .client suffix. Registering a component touches no browser API, and the no-DOM suite imports the Nuxt entry with window and document undefined. Keep the plugin universal: the server render has to resolve <ScrollDraw> as well, and Nuxt does not load a .client plugin there.

The six take options in different ways. <ScrollDraw> declares every draw option as its own prop, and <ScrollCounter> declares to, from, format, easing, trigger, once, decimals and onComplete. <ScrollAnimate>, <ScrollText> and <ScrollVideo> take one options object. Beside it, <ScrollText> has tag (a <p> by default), and <ScrollVideo> has the required src plus muted and playsInline, both true unless you bind false. <ScrollFrames> declares each film option as its own prop, frames required, and renders a <canvas role="img"> that wants an aria-label. A split written straight on <ScrollText> is not a prop, so Vue puts it on the element as an attribute.

pages/launch.vue16 lines
<template>
  <main>
    <!-- No imports: the plugin registered these by name. The comment sits
         inside <main> because a Nuxt page needs one root element, and a
         comment beside it counts as a second. -->
    <ScrollText tag="h2" :options="{ split: 'words', stagger: 0.08 }">
      Ready when you scroll.
    </ScrollText>

    <ScrollAnimate :options="{ props: { opacity: [0, 1] }, once: true }">
      <img src="/launch.png" alt="" />
    </ScrollAnimate>

    <p>Rated <ScrollCounter :to="4.8" :decimals="1" /> out of 5</p>
  </main>
</template>
04ssr

What the server sends

On the server each component renders its element and nothing more. So the HTML Nuxt sends is your content as written: <ScrollDraw> is a <div> around your SVG with every stroke fully drawn, <ScrollText> holds its sentence as plain text, and <ScrollVideo> is a <video> with preload="auto" already set. The dash styles that hide the strokes, and the split into spans with its aria-label, are written by the engine once onMounted runs in the browser, after hydration.

<ScrollCounter> renders its final number (to, through decimals or format), so the figure is in the server HTML for crawlers and for readers before the scripts load (2.26.1+; it was an empty <span> before). On mount the engine takes the text over and writes the value for the current scroll position, which is from (0 by default) until the trigger starts. With useScrollCounter on your own element, put the final value inside it yourself, as below. A reader who asks for reduced motion gets the final value straight away.

components/SignupCount.vue14 lines
<script setup lang="ts">
import { useScrollCounter } from 'svg-scroll-draw/nuxt';

const grouped = new Intl.NumberFormat('en-US');
const signups = useScrollCounter({
  to: 48210,
  format: (n) => grouped.format(Math.round(n)),
});
</script>

<template>
  <!-- The server sends 48,210; the client counts up to it. -->
  <span ref="signups">48,210</span>
</template>
05imports

Importing by hand

Without the module, Nuxt's auto-imports do not know useScrollDraw or the components, because Nuxt scans your own components/ and composables/ directories, not packages. Import them at the top of <script setup>, from svg-scroll-draw/nuxt or svg-scroll-draw/vue.

Mixing the two entry points costs nothing. In the ESM build svg-scroll-draw/nuxt and svg-scroll-draw/vue import their wrappers from one shared chunk, so a component copied from a Vue example that imports from /vue can sit beside one that imports from /nuxt without loading the wrappers or the engines twice. createScrollDrawPlugin and the module are the only runtime exports the Vue entry lacks.

components/Hero.vue9 lines
<script setup>
import { useScrollDraw } from 'svg-scroll-draw/nuxt';

const container = useScrollDraw({ easing: 'ease-out', speed: 1.2 });
</script>

<template>
  <div ref="container"><svg>…</svg></div>
</template>
06size

Size

svg-scroll-draw/nuxt is 16.1 KB gzipped, the engines it wraps included.

svg-scroll-draw/nuxtNuxt, every engine it wraps16.1 KB
scrollRevealits own entry point, for a reveal-only page6.1 KB
gsap 3.15.0GSAP + ScrollTrigger + DrawSVG47.5 KB
Fig. 02 — the same work, to one scale

Measured 2026-08-14 at gzip level 9 against gsap 3.15.0 and svg-scroll-draw 2.31.0. Full comparison →

07Questions

Nuxt questions

Q1

How do I add scroll animations to Nuxt?

Install svg-scroll-draw and add 'svg-scroll-draw/nuxt' to modules in nuxt.config. Every component (<ScrollDraw>, <ScrollAnimate>, <ScrollCounter>, <ScrollVideo>, <ScrollFrames>, <ScrollText>) and composable is then auto-imported. It works in Nuxt 3 and 4 and adds no dependencies.

Q2

Is it SSR-safe in Nuxt?

Yes. Initialisation happens in onMounted, so nothing runs during server rendering and there is no window or document access on the server. No <ClientOnly> wrapper is needed.

Q3

Should I use the module or import by hand?

The module, in most apps: it only adds auto-import entries, and Nuxt imports a component or composable where a page uses it. Import by hand if your team prefers explicit imports; both use the same Vue wrappers. createScrollDrawPlugin() is still there for apps that register components globally.

08Other frameworks

Other frameworks