CSS Animation Example: Staggered List Slide
The "Staggered List Slide" creates an organized, cascading entrance for menu items, guiding the user's eye down the list.
- Dashboard
- Profile
- Settings
- Logout
This animation utilizes a single @keyframes block that animates opacity and transform: translateX(). However, the secret sauce is applying an increasing animation-delay to each sequential list item using the :nth-child() pseudo-class. When a parent class (like .show) is added via JavaScript, all items begin their animation sequence, but uniquely delayed.
Here is the code to create the Staggered List Slide animation.
Accessibility Considerations
While elegant, cascading sliding motions can be aggravating for users with vestibular issues. We can use the prefers-reduced-motion media query to swap the sliding animation for a simple, quick fade-in effect. prefers-reduced-motion is a CSS media feature used to detect if a user has enabled a setting on their operating system or browser to minimize the amount of non-essential animation or motion.
Here's what we used in our example:
@media (prefers-reduced-motion: reduce) {
.staggered-list.show li {
/* Swap out the slide for a gentle fade on the original spot */
animation: simpleFade 0.3s ease forwards;
}
@keyframes simpleFade {
to { opacity: 1; transform: translateX(-20px); }
}
}