Last active
April 8, 2019 10:31
-
-
Save jesseyuen/ad6177a7a905401113157af8b2e9d02b to your computer and use it in GitHub Desktop.
Code examples for Reduced Motion Queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updated to public