Astro scroll animation

Astro’s whole premise is shipping no JavaScript unless you ask for it, so a component wrapper that forces hydration would defeat the point. Here the markup stays a server component: mark elements with data-scroll-draw, pass options as a JSON attribute, and call initScrollDraw() once from a client script. One small script for the whole page, no island per animation.

07data-scroll-draw · initScrollDraw()

The code

A walking journal’s long-read, built the Astro way: the botanical plate carries one data-scroll-draw attribute with its options as JSON, and a single initScrollDraw() call draws the fern as you read down to it.

Hero.tsx17 lines
---
// FernPlate.astro — no framework, one attribute
---
<figure class="plate">
  <div
    data-scroll-draw
    data-scroll-draw-options='{"easing":"ease-out","stagger":0.02,"once":true}'
  >
    <svg viewBox="0 0 360 420">…</svg>
  </div>
  <figcaption>Plate 1 · Asplenium scolopendrium</figcaption>
</figure>

<script>
  import { initScrollDraw } from 'svg-scroll-draw/astro';
  initScrollDraw();   // finds every [data-scroll-draw]
</script>
Fieldnotes, a quarterly journal of walking and noticing: the first screen of its demo site

A quarterly journal of walking and noticing

Fieldnotes

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 →