Composables

useWaapiAnimate

Run Web Animations API animations with AnimeJS waapi.animate().
Instant play

useWaapiAnimate wraps the waapi.animate function from AnimeJS. It animates DOM elements through the browser's Web Animations API instead of a JavaScript loop.

When target or reactive parameters change, nanime rebuilds the animation. It reverts when the component unmounts.

Usage

import { stagger } from '#nanime/utils'

const eases = ['outBack(3)', 'inOutExpo', 'outElastic(1, .5)', 'steps(6)']

const boxes = useTemplateRef('boxes')
const ease = ref<string>(eases[0])

useWaapiAnimate(boxes, () => ({
  transform: ['translateY(-24px)', 'translateY(0px)'],
  ease: ease.value,
  duration: 1000,
  delay: stagger(80),
  alternate: true,
  loop: true,
}))
View on GitHub

Signature

function useWaapiAnimate(
  target: WaapiTargets,
  parameters?: MaybeRefOrGetter<WAAPIAnimationParams>
): WAAPIAnimation

Parameters

target
WaapiTargets required
The DOM element or elements to animate. Accepts CSS selectors, DOM elements, and component or template refs. WAAPI cannot animate plain objects, so use useAnimate for those.
parameters
MaybeRefOrGetter<WAAPIAnimationParams>
Accepts a plain object, a ref or a getter. The animation rebuilds when it changes. See the AnimeJS WAAPI documentation for the options.

Returns

Returns a reactive proxy around the AnimeJS WAAPIAnimation. Its methods and properties are in the AnimeJS WAAPI documentation. Call methods on the returned object, as in animation.play(), because a destructured method throws. progress doesn't update a template either.

Caveats

Do not destructure the returned instance

// wrong: play() throws when called
const { play } = useWaapiAnimate('.target', parameters)

// right
const animation = useWaapiAnimate('.target', parameters)
animation.play()

The proxy hands back methods without their instance, so a destructured play() runs with no this and throws. A destructured property such as progress is a copy of the value at that moment. Keep the returned object and call methods on it.

Properties do not update templates

// wrong: progress never updates inside a template interpolation
// <p>{{ animation.progress }}</p>

Interpolating properties like progress in a template displays only their initial value. WAAPIAnimation has no per-frame callback, so nothing tells Vue when progress changes. useAnimate runs its own render loop and exposes an onUpdate callback instead, so reach for it when a template needs to track progress live.

Type reference

See also

Copyright © 2026