shepherd icon indicating copy to clipboard operation
shepherd copied to clipboard

Use "prefers-reduced-motion" media query to disable animations

Open thejimbirch opened this issue 2 years ago • 5 comments

To turn animations off, you could write a prefers-reduced-motion media query. Then anyone who wants to turn animations off can do so in thue browser/OS settings.

This is from WCAG 2.1 Animations from interactions success criterion, level-AAA.

Discussed in Drupal Issue 2312805 . Drupal previously used jQuery Joyride, and has switched to Shepherd.

thejimbirch avatar Oct 04 '21 23:10 thejimbirch

@thejimbirch you can override scrollTo on the step to change the scrolling behavior if that's what you mean?

RobbieTheWagner avatar Oct 04 '21 23:10 RobbieTheWagner

Thanks for the quick reply!

I like the scrolling. But some users do not.

Was reading the doc at Mozilla about this type of media query is the best of both worlds. Keeps it as a default, but lets users opt out if they so choose.

thejimbirch avatar Oct 05 '21 00:10 thejimbirch

@thejimbirch do you know of a good way to use that with scrollIntoView?

RobbieTheWagner avatar Oct 05 '21 00:10 RobbieTheWagner

This article has a nice example for implementing in JavaScript.

const mediaQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
mediaQuery.addEventListener('change', () => {
  console.log(mediaQuery.media, mediaQuery.matches);
  // Stop JavaScript-based animations.
});

https://web.dev/prefers-reduced-motion/

And a demo at the bottom of the article.

thejimbirch avatar Oct 05 '21 00:10 thejimbirch

This is an important accessibility issue for folks with VIMS. Nobody wants to become sick from browsing the web.

More links

  • https://css-tricks.com/introduction-reduced-motion-media-query/
  • https://scottvinkle.me/blogs/work/animation
  • https://www.tpgi.com/short-note-on-prefers-reduced-motion-and-puzzled-windows-users/

mgifford avatar Dec 08 '21 16:12 mgifford