Good Code
The good version keeps the state change readable while shortening the transition for users who prefer reduced motion.
Lesson 10
Make motion purposeful and respect users who request less animation.
.drawer {
/* State-driven motion can be shortened for reduced-motion users. */
transform: translateX(100%);
transition: transform 180ms ease;
}
.drawer[data-open="true"] {
transform: translateX(0);
}
@media (prefers-reduced-motion: reduce) {
.drawer {
transition-duration: 1ms;
}
}.drawer {
/* The animation runs for everyone and does not expose a reduced path. */
animation: slide-in 600ms cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes slide-in {
from {
transform: translateX(100%);
}
to {
transform: translateX(0);
}
}The good version keeps the state change readable while shortening the transition for users who prefer reduced motion.
The bad version forces the same animation on every user and hides the open state inside an animation that cannot easily respond to user preferences.