Vue.js course Β· Module 13: Transitions & Animations

Project: NOVA LAB Animation System

3 min read Β·
In this lesson4

Time to combine all animation techniques into a cohesive space station interface system! In this project, you'll create a complete NOVA LAB dashboard that uses <Transition>, <TransitionGroup>, named transitions, out-in mode, staggered animations, appear, and accessibility - everything you've learned in this module.

Module Summary

In this module you learned:

  • <Transition> - animating enter/leave of single elements with 6 CSS classes
  • Named Transitions - defining multiple animation types with the name attribute
  • Transition Modes (mode) - controlling animation order when switching views (out-in, in-out)
  • JavaScript Animation Hooks - full control over animations through @enter, @leave, and the done() callback
  • <TransitionGroup> - animating lists with v-for, the -move class for shifting elements
  • Library Integration - custom class names for Animate.css, GSAP through JS hooks
  • Route Transitions - smooth page transitions with <RouterView>
  • Appear - animation on first render, staggered loading
  • Accessibility - respecting prefers-reduced-motion

Project Requirements

Build an Animated NOVA LAB Station Dashboard with the following elements:

1. Control Panel with Fade Animation

A main panel that can be shown/hidden with a button. Use <Transition name="fade"> with v-if.

2. View Switching with out-in Mode

Inside the panel, implement tabs (e.g., "Status" and "Alerts"). Switching between them should use <Transition name="slide" mode="out-in"> with a dynamic :key.

3. Alert List with TransitionGroup

In the "Alerts" tab, display a list of alerts with the ability to add and remove items. Use <TransitionGroup name="list"> with enter, leave, and move classes.

4. Staggered Loading of Elements on Mount

The station modules list should appear in a cascading fashion when the application loads. Use <TransitionGroup appear :css="false"> with JS hooks and delay based on index.

5. Accessibility

Add support for prefers-reduced-motion - users who don't want animations should see instant changes without transitions.

Architecture

App.vue
β”œβ”€β”€ Toggle Button (show/hide panel)
β”œβ”€β”€ Control panel (Transition name="fade")
β”‚   β”œβ”€β”€ Tabs (status / alerts)
β”‚   β”‚   └── Transition name="slide" mode="out-in"
β”‚   β”‚       β”œβ”€β”€ Status view
β”‚   β”‚       β”‚   └── System metrics display
β”‚   β”‚       └── Alerts view
β”‚   β”‚           β”œβ”€β”€ Add alert button
β”‚   β”‚           └── TransitionGroup name="list"
β”‚   β”‚               └── Alert items (add/remove)
β”‚   └── System modules list (TransitionGroup appear :css="false")
β”‚       └── Staggered items (delay based on index)

Key Patterns to Apply

  1. Nested Transitions - fade on the panel, slide on the tabs, list on the alerts
  2. Multiple techniques in one project - CSS transitions (fade, slide), CSS move (list), JS hooks (stagger)
  3. TransitionGroup with move - adding an alert at the beginning of the list causes the rest to smoothly shift
  4. Appear with stagger - cascading module loading creates the effect of "station systems powering up"
  5. The done() callback - in JS hooks, remember to call done() after the animation finishes

Try extending the project with additional effects - for example, a bounce animation for critical alerts or a pulse effect for active modules!

Code for this lesson: App.vue
<script setup>
import { ref } from 'vue'

const showPanel = ref(false)
const alerts = ref([
  { id: 1, text: 'System life support: OK', type: 'success' },
  { id: 2, text: 'Oxygen level: 21%', type: 'info' }
])
const currentView = ref('status')
let alertId = 3

function addAlert() {
  const texts = [
    'Temperature anomaly detected',
    'Solar panel efficiency: 87%',
    'Comm relay signal strong',
    'Water recycler maintenance due'
  ]
  alerts.value.push({
    id: alertId++,
    text: texts[Math.floor(Math.random() * texts.length)],
    type: Math.random() > 0.5 ? 'info' : 'success'
  })
}

function removeAlert(id) {
  alerts.value = alerts.value.filter(a => a.id !== id)
}
</script>

<template>
  <div class="nova-lab">
    <h1>NOVA LAB - Animation System (Project)</h1>

    <!-- Panel toggle with fade transition -->
    <button @click="showPanel = !showPanel" class="btn primary">
      {{ showPanel ? 'Close' : 'Open' }} control panel
    </button>

    <Transition name="fade">
      <div v-if="showPanel" class="control-panel">
        <h2>Control Panel</h2>

        <!-- View switcher with slide + out-in -->
        <div class="tabs">
          <button @click="currentView = 'status'" :class="{active: currentView === 'status'}">Status</button>
          <button @click="currentView = 'alerts'" :class="{active: currentView === 'alerts'}">Alerts</button>
        </div>

        <Transition name="slide" mode="out-in">
          <div v-if="currentView === 'status'" key="status" class="view">
            <p>All systems operational</p>
          </div>
          <div v-else key="alerts" class="view">
            <button @click="addAlert" class="btn small">+ Alert</button>
            <TransitionGroup name="list" tag="div">
              <div v-for="alert in alerts" :key="alert.id" :class="['alert', alert.type]">
                {{ alert.text }}
                <button @click="removeAlert(alert.id)" class="close">Γ—</button>
              </div>
            </TransitionGroup>
          </div>
        </Transition>
      </div>
    </Transition>
  </div>
</template>

<style scoped>
.nova-lab {
  background: #0a0e27;
  color: #00ff88;
  min-height: 100vh;
  padding: 20px;
  font-family: monospace;
}
h1, h2 { color: #00ff88; }
.btn { border: none; padding: 10px 16px; border-radius: 8px; cursor: pointer; color: white; }
.primary { background: #00b4d8; margin-bottom: 15px; }
.small { background: #9b59b6; font-size: 12px; padding: 6px 12px; margin-bottom: 10px; }

.control-panel {
  background: rgba(0, 180, 216, 0.05);
  border: 2px solid #00b4d8;
  padding: 20px;
  border-radius: 12px;
}
.tabs { display: flex; gap: 8px; margin: 10px 0; }
.tabs button {
  background: rgba(0,180,216,0.1);
  color: #00b4d8;
  border: 1px solid #00b4d8;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
}
.tabs button.active { background: #00b4d8; color: white; }

.view { min-height: 100px; }
.alert {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  margin: 6px 0;
  border-radius: 6px;
}
.alert.success { background: rgba(0,255,136,0.1); border: 1px solid #00ff88; }
.alert.info { background: rgba(0,180,216,0.1); border: 1px solid #00b4d8; }
.close { background: transparent; border: none; color: #e74c3c; cursor: pointer; font-size: 16px; }

/* Fade */
.fade-enter-active, .fade-leave-active { transition: opacity 0.4s ease; }
.fade-enter-from, .fade-leave-to { opacity: 0; }

/* Slide */
.slide-enter-active, .slide-leave-active { transition: all 0.3s ease; }
.slide-enter-from { opacity: 0; transform: translateX(20px); }
.slide-leave-to { opacity: 0; transform: translateX(-20px); }

/* List */
.list-enter-active, .list-leave-active { transition: all 0.3s ease; }
.list-enter-from, .list-leave-to { opacity: 0; transform: translateX(30px); }
.list-move { transition: transform 0.3s ease; }
.list-leave-active { position: absolute; }
</style>

Spotted a mistake in this lesson?

  1. Project to submitMentor Link: Transitions & Animations
  2. VideoModule Summary

Useful articles