0
0
Svelteframework~20 mins

Transition parameters (duration, delay) in Svelte - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Svelte Transition Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the visible effect of this Svelte transition code?

Consider this Svelte component snippet using a fade transition with a duration of 1000ms and a delay of 500ms:

<script>
  import { fade } from 'svelte/transition';
  let visible = false;
</script>

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

{#if visible}
  <div transition:fade={{ duration: 1000, delay: 500 }}>Hello</div>
{/if}

What will the user see when toggling the visibility on?

Svelte
<script>
  import { fade } from 'svelte/transition';
  let visible = false;
</script>

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

{#if visible}
  <div transition:fade={{ duration: 1000, delay: 500 }}>Hello</div>
{/if}
AThe 'Hello' text appears after 0.5 seconds delay, then fades in over 1 second.
BThe 'Hello' text appears immediately and fades in over 1 second.
CThe 'Hello' text appears immediately and fades out over 1 second.
DThe 'Hello' text appears after 1 second delay, then fades in instantly.
Attempts:
2 left
💡 Hint

Think about what the delay parameter does before the transition starts.

📝 Syntax
intermediate
1:30remaining
Which option correctly sets a 2-second duration and 300ms delay for a Svelte slide transition?

Choose the correct syntax to apply a slide transition with a duration of 2000 milliseconds and a delay of 300 milliseconds.

Atransition:slide({ duration: 2000, delay: 300 })
Btransition:slide(duration=2000, delay=300)
Ctransition:slide={{ duration: 2000, delay: 300 }}
Dtransition:slide=[duration: 2000, delay: 300]
Attempts:
2 left
💡 Hint

Remember that Svelte transition parameters use double curly braces with key-value pairs.

state_output
advanced
2:00remaining
What is the total time before the element fully appears with this transition?

Given this Svelte code snippet:

{#if show}
  <div transition:fly={{ duration: 1500, delay: 700 }}>Welcome</div>
{/if}

If show becomes true at time 0, after how many milliseconds will the element be fully visible?

Svelte
{#if show}
  <div transition:fly={{ duration: 1500, delay: 700 }}>Welcome</div>
{/if}
A700 milliseconds
B2200 milliseconds
C1500 milliseconds
D800 milliseconds
Attempts:
2 left
💡 Hint

Add the delay and duration times to find the total transition time.

🔧 Debug
advanced
2:00remaining
Why does this Svelte transition not delay as expected?

Look at this Svelte code:

{#if visible}
  <div transition:fade={{ duration: 1000, delay: '500' }}>Hi</div>
{/if}

The developer expects a 500ms delay before fade starts, but the delay seems ignored. Why?

Svelte
{#if visible}
  <div transition:fade={{ duration: 1000, delay: '500' }}>Hi</div>
{/if}
AThe delay value is a string instead of a number, so it is ignored.
BThe fade transition does not support delay parameter.
CThe duration must be a string, not a number.
DThe transition must be wrapped in a function to accept parameters.
Attempts:
2 left
💡 Hint

Check the data type of the delay parameter.

🧠 Conceptual
expert
2:30remaining
How do duration and delay parameters affect the lifecycle of a Svelte transition?

In Svelte transitions, what is the correct relationship between duration and delay parameters regarding the element's lifecycle during enter and leave?

ADelay controls the speed of the transition; duration postpones the element's insertion or removal.
BDuration delays the start of the transition; delay controls how long the transition runs, affecting element visibility timing.
CDelay and duration both control the total time the element stays visible before removal, but do not affect transition speed.
DDelay postpones the start of the transition; duration controls how long the transition runs after delay, affecting when the element is fully visible or removed.
Attempts:
2 left
💡 Hint

Think about what happens first: waiting or transitioning.