0
0
SASSmarkup~20 mins

Animation mixin patterns in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Animation Mixin Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2:00remaining
What is the output CSS of this Sass animation mixin usage?
Given the Sass code below, what CSS will be generated for the .box class?
SASS
@mixin fadeIn($duration) {
  animation-name: fadeIn;
  animation-duration: $duration;
  animation-fill-mode: forwards;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.box {
  @include fadeIn(2s);
}
A
.box {
  animation-name: fadeIn;
  animation-duration: 2s;
  animation-fill-mode: backwards;
}
B
.box {
  animation-name: fadeIn;
  animation-duration: 2;
  animation-fill-mode: forwards;
}
C
.box {
  animation-name: fadeIn;
  animation-duration: 2s;
  animation-fill-mode: forwards;
}
D
.box {
  animation-name: fadeOut;
  animation-duration: 2s;
  animation-fill-mode: forwards;
}
Attempts:
2 left
💡 Hint
Check how the mixin uses the $duration parameter and the animation-fill-mode property.
🧠 Conceptual
intermediate
1:30remaining
Which option correctly explains the benefit of using animation mixins in Sass?
Why do developers use animation mixins in Sass instead of writing animation CSS directly each time?
AThey automatically optimize animations for all browsers without extra code.
BThey allow reusing animation code with different parameters, reducing repetition and errors.
CThey convert animations into JavaScript for better performance.
DThey prevent animations from running on mobile devices by default.
Attempts:
2 left
💡 Hint
Think about how mixins help with writing CSS faster and cleaner.
selector
advanced
2:00remaining
Which Sass selector usage correctly applies an animation mixin only on hover?
Given the mixin @mixin slideRight($time), which option applies it only when the user hovers over .menu-item?
SASS
@mixin slideRight($time) {
  animation-name: slideRight;
  animation-duration: $time;
  animation-fill-mode: forwards;
}

@keyframes slideRight {
  from { transform: translateX(0); }
  to { transform: translateX(100px); }
}
A
.menu-item {
  &:hover {
    @include slideRight(1s);
  }
}
B
.menu-item:hover {
  @include slideRight(1s);
}
C
.menu-item {
  @include slideRight(1s);
  &:hover {
    animation-play-state: paused;
  }
}
D
.menu-item:hover {
  animation-name: slideRight;
  animation-duration: 1s;
  animation-fill-mode: forwards;
}
Attempts:
2 left
💡 Hint
Consider Sass nesting and how mixins are included inside selectors.
layout
advanced
1:30remaining
How does using animation mixins affect CSS file size and maintainability?
Consider a large project with many animations. What is the main layout-related benefit of using animation mixins in Sass?
AThey reduce CSS file size by generating only needed animation code and improve maintainability by centralizing animation logic.
BThey increase CSS file size because mixins duplicate code everywhere they are included.
CThey automatically convert animations into CSS Grid layouts.
DThey force all animations to run simultaneously, improving layout speed.
Attempts:
2 left
💡 Hint
Think about how mixins help organize code and avoid repetition.
accessibility
expert
2:30remaining
Which Sass animation mixin pattern best supports users who prefer reduced motion?
How can you write a Sass animation mixin that respects users' system preference for reduced motion?
A
@mixin fadeInReduced($duration) {
  animation-name: fadeIn;
  animation-duration: $duration;
  animation-fill-mode: forwards;
  @media (prefers-reduced-motion: reduce) {
    animation-delay: 0s;
  }
}
B
@mixin fadeInReduced($duration) {
  animation-name: fadeIn;
  animation-duration: $duration;
  animation-fill-mode: forwards;
  @media (prefers-reduced-motion: reduce) {
    animation-play-state: paused;
  }
}
C
@mixin fadeInReduced($duration) {
  animation-name: fadeIn;
  animation-duration: $duration;
  animation-fill-mode: forwards;
  @media (prefers-reduced-motion: reduce) {
    animation-duration: 0s;
  }
}
D
@mixin fadeInReduced($duration) {
  @media (prefers-reduced-motion: reduce) {
    animation: none !important;
  }
  @media (prefers-reduced-motion: no-preference) {
    animation-name: fadeIn;
    animation-duration: $duration;
    animation-fill-mode: forwards;
  }
}
Attempts:
2 left
💡 Hint
Consider how to completely disable animations for users who want reduced motion.