diff --git a/_includes/techniques/changelog/21.html b/_includes/techniques/changelog/21.html index bb1ee7cca7..8c4502d903 100644 --- a/_includes/techniques/changelog/21.html +++ b/_includes/techniques/changelog/21.html @@ -1,5 +1,6 @@
prefers-reduced-motion
query in JavaScript to prevent motion+ JavaScript animation which causes motion that is triggered by user interactions. +
+The objective of this technique is to allow users to prevent animation from being displayed on web pages, by using JavaScript to evaluate the prefers-reduced-motion
CSS Media Query.
Some users experience distraction or nausea from animated content. For example, if scrolling a page causes elements to move (other than the essential movement associated with scrolling the content, which is under the user's control) it can trigger vestibular disorders.
+Media queries that selectively enable/disable JavaScript-driven animations based on operating system or user agent preferences allow users to prevent those symptoms.
+The understanding document for Motion Actuation includes links for changing the 'Reduce Motion' setting.
+prefers-reduced-motion
CSS Media Query in JavaScriptUsers can indicate their motion preference for interfaces in their system. This choice can be detected in JavaScript by evaluating the prefers-reduced-motion
CSS Media Query. The script can then decide to enable or disable animation effects based on the result of the media query test.
const mediaQueryList = window.matchMedia("(prefers-reduced-motion: no-preference)");
+
+if (mediaQueryList.matches) {
+ /* The user has not expressed a preference for reduced motion – run JavaScript-based animation */
+}
+
+ For each interactive element that moves due to a user interaction:
+prefers-reduced-motion
query to prevent motionThe objective of this technique is to allow users to prevent animation from being displayed on web pages, via the use of the prefers-reduced-motion
CSS Media Query.
Some users experience distraction or nausea from animated content. For example, if scrolling a page causes elements to move (other than the essential movement associated with scrolling) it can trigger vestibular disorders. Enclosing the CSS that creates the animations in a media query allows people to prevent those symptoms.
-A typical example is 'parallax scrolling', where backgrounds move at different rates. The movement due to scrolling the page is essential (and under the users control), but additional movement triggered by the scrolling can also trigger vestibular symptoms.
-The understanding document for Motion Actuation includes links for changing the reduce motion setting.
+Some users experience distraction or nausea from animated content. For example, if scrolling a page causes elements to move (other than the essential movement associated with scrolling the content, which is under the user's control) it can trigger vestibular disorders.
+Media queries that selectively enable/disable CSS-driven animations based on operating system or user agent preferences allow users to prevent those symptoms.
+The understanding document for Motion Actuation includes links for changing the 'Reduce Motion' setting.
Users can indicate their motion preference for interfaces in their system and the 'prefers-reduced-motion' CSS Media Query will respect that choice. CSS can then be applied to disable that motion for users that request it.
-@media (prefers-reduced-motion: reduce) {
+ prefers-reduced-motion
CSS Media Query
+ Users can indicate their motion preference for interfaces in their system and the prefers-reduced-motion
CSS Media Query will respect that choice. CSS can then be applied to disable that motion for users that request it.
+/* CSS for the motion effect */
+
+@media (prefers-reduced-motion: reduce) {
/* CSS to disable motion goes here */
}
Working example of 'prefers-reduced-motion' CSS Media Query
+ Alternatively, it is possible to take the inverse approach: define static styles, and then include a media query that only applies when the user has not set the reduced motion preference.
+/* "Static" CSS styles */
+
+@media (prefers-reduced-motion: no-preference) {
+ /* CSS for the motion effect goes here */
+}
For each interactive element that moves due to a user interaction:
prefers-reduced-motion
CSS media query. When the user enables the reduce motion preference,
the page-flipping animation is turned off.prefers-reduced-motion
prefers-reduced-motion
in Webkit