Challenge - 5 Problems
Svelte Custom Transitions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Svelte custom transition?
Consider this Svelte component using a custom fade transition. What will be the opacity of the element at half the transition duration?
Svelte
<script> import { cubicOut } from 'svelte/easing'; function fade(node, { delay = 0, duration = 400 }) { return { delay, duration, css: t => `opacity: ${t}; transform: scale(${t});`, easing: cubicOut }; } </script> <div transition:fade={{ duration: 400 }}> Hello!</div>
Attempts:
2 left
💡 Hint
The easing function cubicOut makes the transition faster at the start and slower at the end.
✗ Incorrect
The transition uses cubicOut easing, so at half the duration the opacity and scale are about 0.875, not exactly 0.5.
📝 Syntax
intermediate2:00remaining
Which option correctly defines a Svelte custom transition function?
Choose the option that correctly defines a custom transition function in Svelte that changes opacity from 0 to 1 over the given duration.
Attempts:
2 left
💡 Hint
The transition function receives the node and an object with parameters.
✗ Incorrect
Option A correctly destructures the parameter object and returns an object with duration and css function.
🔧 Debug
advanced2:00remaining
Why does this custom transition not animate the element?
This Svelte component uses a custom transition but the element appears instantly without animation. What is the cause?
Svelte
<script> function slide(node) { return { duration: 300, css: t => `transform: translateX(${t * 100}px);` }; } </script> <div transition:slide> Slide me </div>
Attempts:
2 left
💡 Hint
Check the range of t and how it affects translateX value.
✗ Incorrect
The css function moves from 0px to 100px instead of from 100px to 0px, so the element jumps instantly to 0px position.
❓ state_output
advanced2:00remaining
What is the final style of the element after this custom transition completes?
Given this Svelte custom transition, what style will the element have after the transition finishes?
Svelte
<script> function grow(node, { duration = 500 }) { return { duration, css: t => `transform: scale(${t}); opacity: ${t}` }; } </script> <div transition:grow={{ duration: 500 }}> Grow me </div>
Attempts:
2 left
💡 Hint
At the end of the transition, t equals 1.
✗ Incorrect
The css function uses t from 0 to 1, so at the end t=1 means scale(1) and opacity 1.
🧠 Conceptual
expert2:00remaining
Which statement about Svelte custom transitions is true?
Select the correct statement about how custom transitions work in Svelte.
Attempts:
2 left
💡 Hint
Think about the role of the css function in custom transitions.
✗ Incorrect
The css function receives t from 0 to 1 and returns CSS styles that Svelte applies during the transition.