0
0
Angularframework~20 mins

Keyframe animations in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Angular Keyframe Animation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when this Angular animation triggers?

Consider this Angular animation trigger attached to a component:

trigger('fadeInOut', [
  transition(':enter', [
    style({ opacity: 0 }),
    animate('500ms ease-in', style({ opacity: 1 }))
  ]),
  transition(':leave', [
    animate('500ms ease-out', style({ opacity: 0 }))
  ])
])

What will the component do when it appears and disappears?

AThe component stays fully visible without any fade effect on enter or leave.
BThe component instantly appears fully visible and then fades out over 500ms when removed.
CThe component fades in over 500ms but disappears instantly without animation when removed.
DThe component fades in from transparent to fully visible over 500ms when added, and fades out to transparent over 500ms when removed.
Attempts:
2 left
💡 Hint

Look at the :enter and :leave transitions and their styles.

📝 Syntax
intermediate
2:00remaining
Which option correctly defines a keyframe animation in Angular?

Angular animations use the keyframes() function to define multiple steps. Which of these options is syntactically correct?

A
animate('1s', keyframes({
  0: style({ opacity: 0 }),
  1: style({ opacity: 1 })
}))
B
animate('1s', keyframes([
  style({ opacity: 0, offset: 0 }),
  style({ opacity: 1, offset: 1 })
]))
C
animate('1s', keyframes([
  { opacity: 0, offset: 0 },
  { opacity: 1, offset: 1 }
]))
D
animate('1s', keyframes(
  style({ opacity: 0 }),
  style({ opacity: 1 })
))
Attempts:
2 left
💡 Hint

Remember that keyframes() takes an array of style() calls with offset values.

🔧 Debug
advanced
2:00remaining
Why does this Angular animation not run on component enter?

Given this animation trigger:

trigger('slideIn', [
  transition('void => *', [
    animate('300ms ease-in', keyframes([
      style({ transform: 'translateX(-100%)', offset: 0 }),
      style({ transform: 'translateX(0)', offset: 1 })
    ]))
  ])
])

The animation does not run when the component appears. What is the likely cause?

AThe component is not using the animation trigger name 'slideIn' in its template, so the animation never starts.
BThe transition state 'void => *' is correct, so the problem is elsewhere.
CThe keyframes are missing the 'opacity' style, so the animation is ignored.
DThe animate duration '300ms' is too short to see any effect.
Attempts:
2 left
💡 Hint

Check if the animation trigger is properly attached to the component's template.

state_output
advanced
2:00remaining
What is the final style of the element after this animation completes?

Consider this Angular animation:

trigger('colorChange', [
  transition('* => *', [
    animate('1s', keyframes([
      style({ backgroundColor: 'red', offset: 0 }),
      style({ backgroundColor: 'blue', offset: 0.5 }),
      style({ backgroundColor: 'green', offset: 1 })
    ]))
  ])
])

After the animation finishes, what background color will the element have?

ARed
BBlue
CGreen
DNo background color (transparent)
Attempts:
2 left
💡 Hint

The last keyframe defines the final style after animation.

🧠 Conceptual
expert
2:00remaining
Why use keyframe animations instead of simple style transitions in Angular?

Angular animations allow both simple style transitions and keyframe animations. Which reason best explains why you would choose keyframes?

AKeyframes allow defining multiple intermediate steps with different styles and timings, enabling complex animations.
BKeyframes run faster than simple style transitions because they use less CPU.
CKeyframes automatically handle browser compatibility issues without extra code.
DKeyframes are easier to write and require less code than simple style transitions.
Attempts:
2 left
💡 Hint

Think about the flexibility keyframes provide compared to a start and end style.