Chapter 40: Vue Animations with v-for

Animations with v-for → using <TransitionGroup>

This is the exact tool that makes todo lists, product grids, search results, chat messages, kanban cards, notification lists, etc. feel alive, smooth and professional instead of just appearing/disappearing abruptly.

When items are added, removed or reordered in a v-for loop, Vue can animate each individual item — and even animate their position changes when the list order changes (that’s the real magic).

Why <TransitionGroup> Instead of <Transition>?

  • <Transition> → works with single elements that appear/disappear (v-if / v-show)
  • <TransitionGroup> → specially made for multiple elements in a list (v-for)

Key differences:

Feature <Transition> <TransitionGroup>
Works with single element many elements (v-for)
Animates position changes? No Yes — move animation when order changes
Renders a wrapper tag? No (unless you set tag) Yes — defaults to <span>, can set tag=”ul”
Required :key? Recommended Mandatory (unique & stable)
Common use-cases modals, alerts, tabs content todo lists, cards, tables rows, messages

Real, Complete Example – Animated Todo List (2026 Style)

vue

Key Lessons & Magic Details (Must Understand)

  1. :key is mandatory Must be unique and stable (never use index as key in animated lists — causes bugs when order changes)

  2. .move class Automatically added when items reorder → lets you animate position shifts smoothly

  3. .leave-active + position: absolute Prevents layout jump when item is removed — item stays in place during exit animation

  4. Staggering (optional – nice effect)

    CSS

    Then in template:

    vue

Quick Reference Table – <TransitionGroup> Essentials

Class Name When it appears Typical CSS you write
*-enter-from Before enter animation starts opacity: 0; transform: translateX(-30px);
*-enter-active During enter animation transition: all 0.4s ease;
*-leave-to End state of leave animation opacity: 0; transform: translateX(30px);
*-leave-active During leave animation transition: all 0.3s ease;
*-move When items reorder (most important) transition: transform 0.4s ease;
*-leave-active + absolute Prevents jump during removal position: absolute; width: 100%;

Pro Tips from Real Projects (Hyderabad 2026)

  • Always use unique stable keys (database ID, UUID, not index)
  • Keep transitions 0.3–0.5 seconds — longer feels sluggish
  • Use cubic-bezier(0.4, 0, 0.2, 1) or ease-out — feels natural
  • Combine with Prefers-reduced-motion media query (accessibility)
  • For very long lists → consider virtual scrolling (vue-virtual-scroller) + TransitionGroup
  • Test on mobile — animations feel different on 60Hz vs 120Hz

Your mini homework:

  1. Build the todo list above
  2. Add stagger delay (each new item appears 0.1s after previous)
  3. Add slide-from-right for new items, slide-to-left for removed
  4. Add “Clear completed” button that removes multiple items at once

Any part confusing? Want full examples for:

  • Animated kanban board (drag & drop + TransitionGroup)?
  • Chat message list with staggered enter?
  • Animated router-view transitions between pages?
  • TransitionGroup + <KeepAlive> for cached tabs?

Just tell me — we’ll animate the next beautiful list together 🚀

Happy animating from Hyderabad! 💙

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *