Components

Transition

Vue's <Transition> with AnimeJS enter and leave animations.

<AnimeTransition> works like Vue's <Transition>, with AnimeJS running the enter and leave animations instead of CSS classes. It takes one child, toggled by v-if, v-show or a changed key.

Chain steps with keyframes

import type { AnimeTransitionAnimation } from '#nanime/types'
import { random } from '#nanime/utils'

const animation: AnimeTransitionAnimation = {
  enter: {
    x: () => [random(-40, 40), 0],
    y: [60, -6, 0],
    scale: [0.6, 1.04, 1],
    opacity: [0, 1, 1],
    duration: 480,
    ease: 'outQuart',
  },
  leave: {
    x: () => [0, random(-60, 60)],
    y: [0, -8, 70],
    scale: [1, 1.06, 0.6],
    opacity: [1, 1, 0],
    duration: 480,
    ease: 'inOut(2)',
  },
}

const visible = ref(true)
View on GitHub

A function value runs each time the element leaves, so each leave goes somewhere new.

API

animation
AnimeTransitionStyleName | AnimeTransitionAnimation
Enter and leave together. A style name sets both, or pass { enter, leave }. Defaults to 'fade': 300ms in and 200ms out. Defaults sets another for the app.
enterAnimation
AnimeTransitionStyleName | AnimationParams
Overrides the enter in animation.
leaveAnimation
AnimeTransitionStyleName | AnimationParams
Overrides the leave in animation.
mode
'default' | 'in-out' | 'out-in'
Order when one element replaces another. Defaults to 'default'.
appear
boolean
Run the enter animation on the first render too. Defaults to false.
waapi
boolean
Run the enter and leave with waapi.animate() instead of animate(). The animation props then take waapi.animate() params. Defaults to false.
completeOnTabHidden
boolean
Jump running animations to their end when the browser tab is hidden. Defaults to false.

With reduced motion on, the element jumps to its end state. See Accessibility.

Vue's transition events pass through, and nanime calls the done callback of @enter and @leave when the animation finishes.

Set enter and leave with animation

App.vue
<AnimeTransition animation="slide-up" />

<AnimeTransition :animation="{ enter: 'slide-up', leave: 'fade' }" />

With animation="fade" and enter-animation="scale", the element enters with scale and leaves with fade.

Swap keyed elements with mode

A
const modes = ['default', 'in-out', 'out-in'] as const

const mode = ref<typeof modes[number]>('out-in')
const current = ref('A')

function swap() {
  current.value = current.value === 'A' ? 'B' : 'A'
}
View on GitHub

out-in waits for the old element to finish leaving, in-out enters the new one first, and default runs both at once.

Keep transitions smooth during hydration with waapi

App.vue
<AnimeTransition waapi :enter-animation="{ opacity: [0, 1], y: [8, 0], duration: 300 }">
  <div v-if="open" class="panel" />
</AnimeTransition>

Hydration keeps the main thread busy, which stalls animate(). The browser runs waapi.animate() animations off the main thread, so they keep playing.

A style that waapi.animate() cannot run, such as one with keyframe objects or a function value, runs on animate() and logs a warning in development.

Finish animations when the tab is hidden

AnimeJS pauses its animations while the browser tab is hidden, so a leaving element stays half faded. Set completeOnTabHidden to jump the component's running animations to their end instead.

To turn it on for every instance, set it in nanime.components in app.config.ts:

app/app.config.ts
export default defineAppConfig({
  nanime: {
    components: { transition: { completeOnTabHidden: true } },
  },
})

transitionGroup and layoutGroup take the same key.

See also

Copyright © 2026