0
0
Vueframework~10 mins

Transition modes (in-out, out-in) in Vue - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Transition modes (in-out, out-in)
Trigger state change
Start transition mode
in-out mode
Enter new element
Leave old element
out-in mode
Leave old element
Enter new element
When a state changes, Vue uses transition modes to decide if the new element enters before the old leaves (in-out) or the old leaves before the new enters (out-in).
Execution Sample
Vue
<template>
  <transition mode="in-out">
    <div v-if="show" key="A">A</div>
    <div v-else key="B">B</div>
  </transition>
</template>
This Vue template toggles between two elements with an in-out transition mode controlling their enter and leave order.
Execution Table
StepTransition ModeCurrent StateActionElement EnteringElement LeavingResulting DOM
1in-outshow = trueInitial renderAnone<div>A</div>
2in-outshow changes to falseStart transitionBAA visible, B entering
3in-outduring transitionNew element enters firstB visibleA visibleBoth visible overlapping
4in-outafter new entersOld element leavesB visibleA removed<div>B</div>
5out-inshow changes to trueStart transitionABB visible, A waiting
6out-induring transitionOld element leaves firstA waitingB removedNo element visible momentarily
7out-inafter old leavesNew element entersA visiblenone<div>A</div>
💡 Transitions complete when entering and leaving elements finish their animations.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5After Step 6Final
showtruefalsefalsefalsetruetruetrue
Element EnteringABBBAAA
Element LeavingnoneAAremovedBremovednone
DOM Content<div>A</div><div>A</div> + <div>B entering</div>Both visible<div>B</div><div>B</div>empty<div>A</div>
Key Moments - 3 Insights
Why does 'in-out' mode show both elements visible at the same time during transition?
Because in 'in-out' mode, the new element enters first before the old element leaves, so both are visible overlapping during the transition (see execution_table rows 2 and 3).
Why is there a moment with no visible element in 'out-in' mode?
In 'out-in' mode, the old element leaves completely before the new element enters, causing a brief moment with no visible element (see execution_table row 6).
What determines which element enters or leaves first?
The transition mode property ('in-out' or 'out-in') controls the order of entering and leaving elements during state changes.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does the new element enter first in 'in-out' mode?
AStep 5
BStep 2
CStep 3
DStep 6
💡 Hint
Check the 'Element Entering' column for 'in-out' mode steps.
At which step in 'out-in' mode does the old element leave completely before the new enters?
AStep 6
BStep 4
CStep 3
DStep 2
💡 Hint
Look for when 'Element Leaving' is 'removed' and 'Element Entering' is still waiting.
If the transition mode is changed from 'in-out' to 'out-in', what changes in the DOM during transition?
ANew element enters before old leaves
BOld element leaves before new enters
CBoth elements enter simultaneously
DNo transition happens
💡 Hint
Compare the 'Action' and 'Resulting DOM' columns for both modes.
Concept Snapshot
Vue transition modes control element enter/leave order:
- in-out: new enters first, old leaves after
- out-in: old leaves first, new enters after
Use mode="in-out" or mode="out-in" on <transition>
Controls smooth visual switching between elements
Full Transcript
This visual trace shows how Vue's transition modes 'in-out' and 'out-in' control the order of entering and leaving elements during state changes. In 'in-out' mode, the new element enters first while the old element is still visible, causing overlap during transition. In 'out-in' mode, the old element leaves completely before the new element enters, causing a brief moment with no visible element. The execution table tracks each step, showing which element enters or leaves and the resulting DOM content. The variable tracker follows the state variable and elements' presence. Key moments clarify common confusions about overlapping visibility and empty moments. The quiz tests understanding of the transition order and effects on the DOM.