Last active
October 28, 2018 20:01
-
-
Save danielpost/2477d1881d9b267b39756068f09be5d2 to your computer and use it in GitHub Desktop.
Reduce motion on your website if it's enabled by the user (https://css-tricks.com/introduction-reduced-motion-media-query/)
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
.some-component { | |
:not(.reduced-motion) & { | |
animation: animation-name 3s linear infinite; | |
} | |
} |
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
((window, document, undefined) => { // eslint-disable-line | |
/** | |
* On DOM ready. We use an unnamed function here to make sure 'this' | |
* equals document. | |
*/ | |
document.addEventListener('DOMContentLoaded', function () { // eslint-disable-line | |
/** | |
* Handle reduced motion #a11y. | |
* | |
* If reduced motion is enabled, we add the .reduced-motion class | |
* to the <html> tag, which we can then target in JS or CSS. | |
*/ | |
{ | |
const motionQuery = window.matchMedia('(prefers-reduced-motion)'); | |
if (motionQuery.matches) { | |
document.documentElement.classList.add('reduced-motion'); | |
} | |
} | |
}); | |
})(window, document); // eslint-disable-line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment