0
0
Svelteframework~10 mins

Transition parameters (duration, delay) in Svelte - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Transition parameters (duration, delay)
Component mounts
Transition starts
Check delay
Wait delay
Animate over duration
Transition ends
Component fully visible
When a component appears, Svelte waits for the delay, then animates the transition over the duration time before finishing.
Execution Sample
Svelte
  <script>
    import { fade } from 'svelte/transition';
  </script>

  <div transition:fade={{ duration: 1000, delay: 500 }}>
    Hello
  </div>
This code fades in a div with a 500ms delay and a 1000ms fade duration.
Execution Table
StepActionDelay TimerAnimation ProgressOutput
1Component mounts0ms0%Div hidden
2Start delay timer0ms0%Waiting...
3Delay timer at 500ms500ms0%Delay finished, start animation
4Animation starts500ms0%Div begins fading in
5Animation at 250ms500ms25%Div partially visible
6Animation at 500ms500ms50%Div half visible
7Animation at 750ms500ms75%Div mostly visible
8Animation at 1000ms500ms100%Div fully visible
9Transition ends500ms100%Div fully visible, transition complete
💡 Animation completes after duration (1000ms) following delay (500ms).
Variable Tracker
VariableStartAfter DelayMid AnimationEnd Animation
delayTimer0ms500ms500ms500ms
animationProgress0%0%50%100%
divOpacity000.51
Key Moments - 2 Insights
Why does the div stay hidden at the start even though the component is mounted?
Because the delay parameter causes Svelte to wait before starting the animation, as shown in execution_table row 2 and 3.
What happens if duration is set to 0?
The animation jumps instantly to fully visible after the delay, skipping gradual fade steps, as duration controls animation length.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the animation progress at step 6?
A50%
B0%
C25%
D75%
💡 Hint
Check the 'Animation Progress' column at step 6 in the execution_table.
At which step does the delay finish and animation start?
AStep 4
BStep 2
CStep 3
DStep 5
💡 Hint
Look for when 'Delay finished, start animation' appears in the 'Output' column.
If delay is set to 0, how would the execution table change?
AAnimation would never start
BDelay timer would stay at 0ms and animation starts immediately
CAnimation progress would start at 50%
DDelay timer would increase beyond 500ms
💡 Hint
Refer to the 'Delay Timer' and 'Output' columns in the execution_table for delay behavior.
Concept Snapshot
Svelte transitions use parameters like duration and delay.
- delay: wait time before animation starts
- duration: how long animation runs
Example: transition:fade={{ duration: 1000, delay: 500 }}
Delay pauses before fade begins.
Duration controls fade speed.
Useful for smooth, timed animations.
Full Transcript
When a Svelte component with a transition mounts, it first checks the delay parameter. If delay is set, Svelte waits that amount of time before starting the animation. After the delay, the animation runs over the duration time, gradually changing the component's appearance, such as fading in. For example, with a delay of 500 milliseconds and duration of 1000 milliseconds, the component stays hidden for 500ms, then fades in over 1 second. Variables like delayTimer track the waiting time, animationProgress tracks how far the animation has run, and divOpacity changes from 0 to 1 during the fade. This process ensures smooth, timed transitions that can be controlled precisely.