framework / vue 3Vue 3 · Vite · Nuxt 3

Vue 3 scroll animations. Composables and components.

Vue gets real wrappers here, not a vanilla escape hatch: a component for the common case and a composable when you need the element ref yourself. Both ship in the same package — there is no separate Vue build — and both tear down on unmount, so nothing leaks across route changes.

API reference →24 live examples →
vue entry
15.6 KB
Every API
11.9 KB
GSAP stack
47.5 KB
Version
2.31.0
01Composable + component

Quick start

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

Or start from a running project: the Vue 3 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 01Hero.vue

    The composable — you own the ref

    Hero.vue18 lines
    <script setup>
    import { useScrollDraw } from 'svg-scroll-draw/vue';
    
    // Returns a ref — bind it to the element wrapping your SVG.
    const container = useScrollDraw({
      easing: 'ease-out',
      speed: 1.2,
      fade: true,
    });
    </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>
  2. sample 02Logo.vue

    The component — no ref wiring

    Logo.vue11 lines
    <script setup>
    import { ScrollDraw } from 'svg-scroll-draw/vue';
    </script>
    
    <template>
      <ScrollDraw :easing="'ease-out'" :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>
    </template>
  3. sample 03Features.vue

    Reveal, counters and text

    Features.vue12 lines
    <script setup>
    import { useScrollAnimate, useScrollCounter, useScrollText } from 'svg-scroll-draw/vue';
    
    const card    = useScrollAnimate({ props: { opacity: [0, 1], transform: ['translateY(24px)', 'translateY(0px)'] } });
    const revenue = useScrollCounter({ to: 48000, format: n => `$${n.toLocaleString()}` });
    const heading = useScrollText({ split: 'words', stagger: 0.05 });
    </script>
    
    <template>
      <h2 ref="heading">Every API, one package.</h2>
      <div ref="card"><span ref="revenue">0</span></div>
    </template>
!worth knowing

The composable returns the ref rather than taking one, so you never have to guard against a null element on first render — the engine only starts after onMounted.

02composables

Pass a getter to keep options live

Each composable takes its options as a plain object, a ref (a computed counts) or a getter function. A getter or a ref is read inside a Vue watch. When a value it reads changes, the old engine is destroyed and a new one starts on the same element with the new values: a scroll-linked draw picks up at the current scroll position, and an autoplay draw plays again from the start once it is in view. A plain object gives the watch nothing to track, so it is read once.

Only the argument is unwrapped, not the fields inside it. With const speed = ref(1), useScrollDraw({ speed }) hands the engine the ref object instead of the number. Write useScrollDraw(() => ({ speed: speed.value })). Props destructured from defineProps() in Vue 3.5 follow the same rule: inside a getter they stay live, in a plain object they are read at setup.

The watch compares a fingerprint of the options (optionsKey), not the object. A getter that returns a new object with the same values rebuilds nothing.

DrawOnScroll.vue19 lines
<script setup>
import { useScrollDraw } from 'svg-scroll-draw/vue';

const { speed = 1, easing = 'ease-out' } = defineProps({
  speed: Number,
  easing: String,
});

// Live: the draw is rebuilt when either prop changes.
const container = useScrollDraw(() => ({ speed, easing }));

// Read once at setup: useScrollDraw({ speed, easing })
</script>

<template>
  <div ref="container">
    <slot />
  </div>
</template>
03re-renders

Re-renders keep the running draw

The components read every option prop inside their watch, but rebuild only when the options differ by value. :trigger="{ start: step.start }" builds a new object each time the parent renders; while step.start holds the same string the contents are equal, so the running draw stays. Vue's template compiler marks a literal with nothing reactive in it, such as :trigger="{ start: 'top 80%' }", as constant and does not pass it again. A different speed, easing name or trigger does rebuild.

Functions count as present or absent, never by identity. The engine gets wrappers that call the latest function under the same name (liveFns), so a callback or a custom easing function that changes between renders takes effect without a rebuild. In an SFC template Vue caches an inline handler such as @progress="p => (pct = p)", so it never changes. One that uses a v-for or slot variable, like @progress="p => (step.pct = p)", is a new function on every render, as is any arrow in a render function or JSX. Adding or removing a callback does rebuild. The browser suite re-renders a real Vue app with a fresh onProgress arrow on <ScrollDraw> and a fresh options object on <ScrollAnimate>, and requires the same engine afterwards.

Only top-level functions are read live. The callbacks inside waypoints stay the ones the engine was built with until something else rebuilds it. One that closes over a ref still reads its current .value.

StepList.vue26 lines
<script setup>
import { reactive } from 'vue';
import { ScrollDraw } from 'svg-scroll-draw/vue';

const steps = reactive([
  { id: 'plan', start: 'top 85%', pct: 0 },
  { id: 'build', start: 'top 70%', pct: 0 },
  { id: 'ship', start: 'top 55%', pct: 0 },
]);
</script>

<template>
  <ol>
    <li v-for="step in steps" :key="step.id">
      {{ step.id }} {{ Math.round(step.pct * 100) }}%
      <!-- Each progress call re-renders the list: a new trigger object
           and a new arrow for every row, equal by value, so no draw
           restarts -->
      <ScrollDraw :trigger="{ start: step.start }" @progress="p => (step.pct = p)">
        <svg viewBox="0 0 240 24" fill="none" stroke="currentColor">
          <path d="M4 12 C 60 2, 180 22, 236 12" />
        </svg>
      </ScrollDraw>
    </li>
  </ol>
</template>
04props

Every option is a prop on <ScrollDraw>

Since 2.19.0 the component declares a prop for each key of ScrollDrawOptions, typed against it with satisfies, so a missing or extra key is a type error. Before, it declared 12: preset, native, axis, strokeColor and the rest landed on the div as attributes and never reached the engine. Kebab-case works (stroke-color), and the callbacks are props too, so @progress, @enter and @leave-back arrive as onProgress, onEnter and onLeaveBack.

Boolean options work bare: <ScrollDraw once fade> passes true for both. clip takes a bare attribute (the left edge) or an edge name, and velocityScale takes a bare attribute or a number. A boolean you leave out stays undefined instead of becoming false, so preset="reveal" keeps the fade and the once it sets, and an absent native still means the native CSS path when the browser and the options allow it.

Attributes that are not options, such as class, id, data-* and aria-*, fall through to the wrapping div as they do on any Vue component. <ScrollAnimate>, <ScrollVideo> and <ScrollText> take their options as one :options object, compared the same way. <ScrollCounter> takes them as props (to, from, format, decimals and the rest) and leaves an absent once to the engine, which defaults it to true.

BrandMark.vue23 lines
<script setup>
import { ScrollDraw } from 'svg-scroll-draw/vue';

const emit = defineEmits(['drawn']);
</script>

<template>
  <!-- preset, stroke-color, once and @complete reach the engine;
       class and aria-hidden land on the div -->
  <ScrollDraw
    preset="sketch"
    stroke-color="#42b883"
    once
    class="brand-mark"
    aria-hidden="true"
    @complete="emit('drawn')"
  >
    <svg viewBox="0 0 200 120" fill="none" stroke="currentColor" stroke-width="8">
      <path d="M20 100 L 60 20 L 100 100" />
      <path d="M100 100 L 140 20 L 180 100" />
    </svg>
  </ScrollDraw>
</template>
05size

Size

svg-scroll-draw/vue is 15.6 KB gzipped, the engines it wraps included.

svg-scroll-draw/vueVue 3, every engine it wraps15.6 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 →

06Questions

Vue 3 questions

Q1

How do I animate on scroll in Vue 3?

Install svg-scroll-draw and import either the ScrollDraw component or the useScrollDraw composable from svg-scroll-draw/vue. The composable returns a template ref you bind to the element wrapping your SVG; the animation is driven by scroll position and cleans up automatically on unmount.

Q2

Does it work with Nuxt 3 and SSR?

Yes. The engine only initialises in onMounted, so nothing touches the DOM during server rendering. Nuxt users can import from svg-scroll-draw/nuxt, which re-exports every Vue composable and component plus a plugin for global registration.

Q3

Is there a Vue alternative to GSAP ScrollTrigger?

svg-scroll-draw covers the common ScrollTrigger cases — scroll-driven animation, pin, snap, parallax, text split, counters and video scrub — at 11.9 KB for every API versus 47.5 KB for GSAP core plus ScrollTrigger plus DrawSVG. GSAP is broader; if you need timelines, Draggable or Flip, use GSAP.

07Other frameworks

Other frameworks