Created
November 22, 2020 17:21
-
-
Save neodigm/c1a9abc96194b5d3eee5eeb355b5ef5a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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(); | |
} | |
// Adds 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