Skip to content

Instantly share code, notes, and snippets.

@vanaf1979

vanaf1979/vanilla-redued-motion.js Secret

Last active Sep 10, 2020
Embed
What would you like to do?
// Grab the prefers reduced media query.
const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
// Check if the media query matches or is not available.
if (!mediaQuery || mediaQuery.matches) {
doSomethingWithoutAnimation();
} else {
doSomethingWithAnimation();
}
// Ads an event listener to check for changes in the media query's value.
mediaQuery.addEventListener("change", () => {
if (mediaQuery.matches) {
doSomethingWithoutAnimation();
} else {
doSomethingWithAnimation();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.