--- title: Use mode="out-in" for Sequential Element Transitions impact: MEDIUM impactDescription: Without transition mode, entering and leaving elements animate simultaneously, causing overlap and layout issues type: best-practice tags: [vue3, transition, animation, mode, out-in, in-out] --- # Use mode="out-in" for Sequential Element Transitions **Impact: MEDIUM** - By default, Vue's `` runs enter and leave animations simultaneously. This causes the old and new elements to overlap during the transition, often resulting in visual glitches, layout jumping, or elements appearing stacked. Use `mode="out-in"` to ensure the old element fully animates out before the new one enters. ## Task Checklist - [ ] Use `mode="out-in"` when transitioning between mutually exclusive elements - [ ] This is especially important for buttons, tabs, or content that shouldn't overlap - [ ] Consider `mode="in-out"` only for specific overlapping effects (rare) - [ ] Without a mode, both animations run in parallel (default behavior) **Problematic Code:** ```vue ``` **Correct Code:** ```vue ``` ## Transition Modes Explained ### No Mode (Default) ``` Time: |----- leave animation -----| |----- enter animation -----| Elements are animated simultaneously (parallel) ``` ### mode="out-in" (Recommended for most cases) ``` Time: |----- leave animation -----| |----- enter animation -----| Old element leaves first, then new element enters (sequential) ``` ### mode="in-out" (Rare use case) ``` Time: |----- leave animation -----| |----- enter animation -----| New element enters first, then old element leaves ``` ## When to Use Each Mode ### Use `mode="out-in"` for: - Toggle buttons (Edit/Save, Play/Pause) - Tab content switching - Multi-step forms - State-based content (Loading/Error/Success) - Any mutually exclusive content ```vue ``` ### Use `mode="in-out"` for: - Card flip effects where new content appears behind old - Specific design requirements where overlap is intentional - Rarely used in practice ```vue ``` ### Use No Mode for: - Cross-fade effects where overlap is desired - Image galleries with smooth blending - Background transitions ```vue ``` ## Handling Absolute Positioning If you must use the default mode (no mode) for non-overlapping elements, use absolute positioning: ```vue ``` ## Reference - [Vue.js Transition Modes](https://vuejs.org/guide/built-ins/transition.html#transition-modes)