Skip to content

Instantly share code, notes, and snippets.

@jesseyuen
Last active April 8, 2019 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesseyuen/ad6177a7a905401113157af8b2e9d02b to your computer and use it in GitHub Desktop.
Save jesseyuen/ad6177a7a905401113157af8b2e9d02b to your computer and use it in GitHub Desktop.
Code examples for Reduced Motion Queries
/*Learn more: https://jesseyuen.com/motion-queries-in-the-wild/*/
/* Quick and dirty attempt to remove ALL the motion */
@media (prefers-reduced-motion) {
*,
*:before,
*:after {
animation: unset !important;
transition: none !important;
}
}
/* Detect users that prefer no motion in your js*/
if (!(window.matchMedia('(prefers-reduced-motion)').matches)) {
// initialsie animation
}
/* Create a utility class for users that prefer no motion */
if (window.matchMedia('(prefers-reduced-motion)').matches) {
document.documentElement.classList.add('prefers-no-motion');
}
/* Nested parent selector example */
.selector {
//styles that include motion
.prefers-no-motion & {
// stop the motion
}
}
@jesseyuen
Copy link
Author

updated to public

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment