Svelte scroll animation

Svelte actions are the right primitive for this — no wrapper component, no extra element in the DOM, just use:scrollDraw on the node you want animated. This example animates a reactive store graph with spring easing, and reaches for createScrollDraw when the instance itself needs handling. Cleanup is automatic through the action lifecycle.

11Svelte · use:scrollDraw

The code

A running app's home page. Sunday's 21 km route traces itself across the map card, then the elevation profile draws beneath it — written here as you would in Svelte with the use:scrollDraw action.

Hero.tsx18 lines
<script>
  import { scrollDraw } from 'svg-scroll-draw/svelte';
</script>

<div
  class="route"
  use:scrollDraw={{ trigger: { start: 'top 85%', end: 'top 25%' },
                    easing: 'ease-in-out', once: true }}
>
  <svg viewBox="0 0 400 260"><path d={route} /></svg>
</div>

<div
  class="elevation"
  use:scrollDraw={{ selector: '.ink', easing: 'ease-out', once: true }}
>
  <svg viewBox="0 0 400 90"><path class="ink" d={profile} /></svg>
</div>
Stride, a running app that draws every route: the first screen of its demo site

A running app that draws every route

Stride

Live site

Related examples

MIT licensed, zero runtime dependencies. Every API is a separate entry point, so you only ship what you import. Full API reference →