0
0
Svelteframework~20 mins

Transition directive (transition:fade) in Svelte - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Fade Transition Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when the fade transition is applied?
Consider a Svelte component that uses transition:fade on a paragraph. What will the user see when the paragraph is removed from the DOM?
Svelte
<script>
  import { fade } from 'svelte/transition';
  let visible = true;
</script>

<button on:click={() => visible = !visible}>Toggle</button>

{#if visible}
  <p transition:fade>This text will fade out when hidden.</p>
{/if}
AThe paragraph slides out to the left before disappearing.
BThe paragraph fades out smoothly before being removed from the DOM.
CThe paragraph instantly disappears without any animation.
DThe paragraph blinks several times before disappearing.
Attempts:
2 left
💡 Hint
Think about what the fade transition does visually.
📝 Syntax
intermediate
2:00remaining
Which option correctly applies the fade transition with a duration of 500ms?
You want to apply the fade transition to a div with a custom duration of 500 milliseconds. Which code snippet is correct?
A<div transition:fade={{ duration: 500 }}>Content</div>
B<div transition:fade={{duration:500}}>Content</div>
C<div transition:fade={{ duration:500 }}>Content</div>
D>vid/<tnetnoC>}} 005 :noitarud {{=edaf:noitisnart vid<
Attempts:
2 left
💡 Hint
Check the syntax for passing parameters to transitions in Svelte.
🔧 Debug
advanced
2:00remaining
Why does the fade transition not run on initial render?
Given this Svelte code, the fade transition does not animate when the paragraph first appears. Why?
Svelte
<script>
  import { fade } from 'svelte/transition';
  let show = true;
</script>

{#if show}
  <p transition:fade>This text appears immediately without fade-in.</p>
{/if}
ASvelte does not run transitions on elements that are present on initial render by default.
BThe fade transition requires an explicit <code>in:fade</code> directive to run on mount.
CThe <code>show</code> variable must be initialized to false for the fade to run.
DThe fade transition only works on elements removed from the DOM, not added.
Attempts:
2 left
💡 Hint
Think about when Svelte applies transitions by default.
state_output
advanced
2:00remaining
What is the value of visible after the fade transition completes?
In this Svelte component, what is the value of visible after the fade transition finishes when toggling off?
Svelte
<script>
  import { fade } from 'svelte/transition';
  let visible = true;

  function toggle() {
    visible = !visible;
  }
</script>

<button on:click={toggle}>Toggle</button>

{#if visible}
  <p transition:fade>This text fades in and out.</p>
{/if}
Avisible never changes because transitions block state updates.
Bvisible toggles back to true automatically after the fade transition.
Cvisible remains true until the fade transition finishes, then becomes false.
Dvisible immediately becomes false when the button is clicked, before the fade starts.
Attempts:
2 left
💡 Hint
Consider when the state variable changes relative to the transition animation.
🧠 Conceptual
expert
3:00remaining
Which statement best describes the difference between transition:fade and in:fade in Svelte?
Choose the option that correctly explains how transition:fade differs from in:fade.
A<code>transition:fade</code> runs only when the element enters the DOM; <code>in:fade</code> runs when it leaves.
B<code>transition:fade</code> disables all animations; <code>in:fade</code> enables fade animations.
C<code>transition:fade</code> runs both when the element enters and leaves the DOM; <code>in:fade</code> runs only when the element enters.
D<code>transition:fade</code> is deprecated and replaced by <code>in:fade</code>.
Attempts:
2 left
💡 Hint
Think about when each directive triggers animations.