Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for prefers-reduced-motion media query #832

Merged
merged 4 commits into from
Jul 23, 2018

Conversation

marcysutton
Copy link
Contributor

Improve accessibility by respecting the user's preference for "reduce motion".

Closes #831

Improve accessibility by respecting the user's preference
@eltonmesquita
Copy link
Collaborator

This is great and something that I wasn't even aware. Thanks for the PR!

I do want to merge it but I'd prefer that it was added directly in the CSS files as it's easier to people to be aware of it. Also, wouldn't be easier to achieve the feature directly with the animated class instead of class by class?

@marcysutton
Copy link
Contributor Author

@eltonmesquita I wasn't sure what would be preferred, it seemed like a lot of boilerplate that people might skip if it had to be manually repeated in every CSS file.

The animated class doesn't define all of the animations, so reduced motion won't match if it is targeted on that class alone. That was where I started, and it didn't work...hence the addition to include every specific animation class.

@eltonmesquita
Copy link
Collaborator

Certainly, to repeat the media query for every animation class is not the best option.

I think that the best options is to change the position of the animated class - that resides on _base.css - to the end of the generated file instead the beginning. This won't have any impact on the library, yet will solve the problem in a more elegant way.

Can you do that? I'll happily merge the PR!

@marcysutton
Copy link
Contributor Author

@eltonmesquita how would the order of .animated matter if the animations and transitions that have to be overridden are all defined on classes like .bounce, .flash, etc.? It's a specificity problem, no?

One other thing I tried was compiling a list of CSS classes into one reduceMotion file with Gulp, but it was super difficult to accomplish and I went for the current solution instead. Maybe that's the way to go, though?

A reduceMotion.css file could end up looking like this, where the applicable classes would get appended to the list of selectors:

@media (prefers-reduced-motion) {
    .animated,
    .bounce,
    .flash,
    ...etc {
        animation-name: unset;
        transform: none !important;
    }
}

@eltonmesquita
Copy link
Collaborator

Sorry, I think that I didn't make myself clear.

The way animate.css works today, you always got to have at least two classes: animated and the animation name's class. Although it's possible to make things work without the animated class it's not advised.

If we set the media query on the animated class and put its declaration in the end of the generated file, everything should work just fine.

What do you think? Would that be a good way to solve the problem?

@daneden
Copy link
Collaborator

daneden commented Jul 21, 2018

This is a great addition, thank you @marcysutton! To @eltonmesquita’s point, we can use the “cascading” part of “CSS” to our advantage here 😊

To clarify, I think the suggestion is that we append rather than prepend the _base.css file in the gulp process so that the .animated class comes last. Then, we only need a media query that sets:

@media (prefers-reduced-motion) {
  .animated {
    animation: none !important;
    transform: none !important;
  }
}

Rather than media queries for each and every animation class.

@marcysutton
Copy link
Contributor Author

Sounds great! I tested it on Friday to make sure it works, just hadn't gotten around to committing a fix yet.

@daneden
Copy link
Collaborator

daneden commented Jul 23, 2018

Thanks for these updates @marcysutton! I'm actually about to merge #834, which might require a rebase here, but would love to get this feature in 3.7.0. Let me know when this is good to go from your POV.

@marcysutton
Copy link
Contributor Author

@daneden I pulled from master and updated my PR, it should be good to go! You can go ahead and squash it into one commit if you like. Thanks for your support!

@daneden daneden merged commit 940e4ae into animate-css:master Jul 23, 2018
@daneden
Copy link
Collaborator

daneden commented Jul 23, 2018

@marcysutton thank you for contributing!!

high-five-ish

@warengonzaga
Copy link
Member

alright, @daneden @marcysutton @eltonmesquita just updated mine and submit a PR...

@diqidoq
Copy link

diqidoq commented Nov 7, 2018

While I fully agree with the addition, I think this is important to document on GH and project homepage. And we maybe should consider 2 compiled min.css. One with and one without. It took days to realize that the reason for animations have stopped lies here and that the CMS using it has wrapped itself into this query which made animate.css stop completely.

@warengonzaga
Copy link
Member

@diqidoq we will consider that one... maybe I can include it as an option when you build your customized version of animate.css let me work on it. :)

@TomCatSK
Copy link

I had a problem with animations in Firefox with these rows in animate.css :

@media (print), (prefers-reduced-motion) {
.animated {
-webkit-animation: unset !important;
animation: unset !important;
-webkit-transition: none !important;
transition: none !important;
}
}

The animations didn't work because of “Turn off all unnecessary animations (when possible).” - setting in Windows system is set to "on". But in Chrome or IE the animations were working and I didn't understand why not in Firefox.

So, I had 3 solutions:

  1. “Turn off all unnecessary animations (when possible).” to set to "off"
    or
  2. add new item to about:config in Firefox - ui.prefersReducedMotion = 0
    or
  3. remove these rows from animate.css

But now I have big question, which solution is right guys?

@warengonzaga
Copy link
Member

Hi @TomCatSK I think we need to add option on turning off and on this feature. @eltonmesquita @daneden what do you think?

@TomCatSK
Copy link

TomCatSK commented Apr 7, 2019

It sounds like a good idea. I agree with you.

kaypeter87 added a commit to kaypeter87/animate.css that referenced this pull request Sep 9, 2019
* Update README.md

Add badge for Npm.

* fix headings (animate-css#685)

* Fix broken Markdown headings (animate-css#689)

* fix a bug (animate-css#709)

Resolve the problem after calling the animateCss() method can not continue to call other jQuery methods

* Made class list a Markdown table (animate-css#698)

* recommend using SRI hashes and `crossover` attributes (animate-css#647)

* Consistent spacing (animate-css#720)

* Add jsDelivr links (animate-css#745)

* Readme file update for using columns on classes names. (animate-css#744)

* Edit autoprefixer browser options (animate-css#721)

New browser options provide wider support for browsers.

* Fixed Custom Builds  (animate-css#695)

* Fixed Custom Builds in order accept partial builds using animate-config.json (bug in gulpfile)

* Update gulpfile.js

* Added callback for jQuery extension (animate-css#601)

Added to the extension for JQuery, callback function.

* Fix

* prettier rules

* Format files

* rename scrip

* EOL

* Update the devDependencies, Fix build failing status, and some minor changes! (animate-css#766)

* Update the devDependencies

* Update the gitignore file

* Update the version of gulp

* Fix the build error in the gulpfile script

* Update node version testing for travis

* Add CDNJS version badge in readme (animate-css#643)

* Update prettier

* Ignore fixed

* More info in editorconfig

* Move css properties to appropriate location (animate-css#761)

* 修改gitignore中的文件 (animate-css#773)

* Update license year (animate-css#775)

* Added npm start script

* Solves animate-css#461

* Fixes animate-css#644

* Added windows thumbs and Desktop.ini to gitignore

* 3.6.0

* Version bump

* 3.6.1

* 😃 Add hertBeat animation as a fix to issue animate-css#829

* Update Readme to include heartBeat animation within the list of animate classes available 👍

* Minor Updates and Small Fixes (animate-css#790)

* Update the devDependencies

* Update the gitignore file

* Update the version of gulp

* Fix the build error in the gulpfile script

* Update node version testing for travis

* Update the package.json

* Fix some errors

* Update the devdependencies

* Re arrange the .gitignore

* Update devdependency to the latest stable version

* Add new line at the end of the file

* Fix versioning error

* Update DevDependencies

* Update the version from 3.6.1 into 3.6.2

* Add delays up to 5 seconds

* Update the files from 3.6.1 into 3.6.2

* Modify the documentation and add delay option

* Verbose opacity (animate-css#788)

* Remove webkit prefixes 🎉

* Bit change in the code structure 😃

* Bit of change in the code structure 😃👍

* Fixed typos 😃

* Fix Firefox flip bug (animate-css#805)

* Resolve merge conflicts

Co-Authored-By: gianjohansen <gian.johansen@gmail.com>

* Add heartBeat to animate.min.css with gulp 🎉

* Resolve conflicts 👍

* Update Readme to use correct build/dev dependency badges

* Add new animation speed & delay classes

3.7.0 New Feature: Animation speed & delay classes, dependency updates

* Add support for prefers-reduced-motion media query (animate-css#832)

Feat: add prefers-reduced-motion media query

Improve accessibility by respecting the user's preference

* Update homepage field (animate-css#859)

* Improved some examples

* add yarn (animate-css#865)

* Fix typo in README.md (animate-css#862)

* Cleaning up the Readme file (animate-css#872)

* Cleaning up the Readme file

* Removed note about CSS prefixes

* Update devdependencies (animate-css#888)

* Update devdependencies
* Replace package-lock file with shrinkwrap

* Turn off animations for print media query (animate-css#881)

Resolves animate-css#856

* Add a feature to turn off animations for printing as requested.
* Add print media type
* Update the builds

* Update examples to pure js. closes animate-css#875 (animate-css#899)

I keept things simple and dropped support for aging browsers in the examples, although IE11 still gets support.

* Updated year on License

* Create CODE_OF_CONDUCT.md

Closes animate-css#902.

* Added Code of conduct to Readme

* Updated prefers-reduced-motion support on readme

*  Fixed the name of the function in README.md (animate-css#915)

`animateCss` to `animateCSS` because that's what is used as an example after.

* Update _base.css

* Update _base.css

* Update _base.css

* Update _base.css

* Compiled source

* 3.7.1

* Upped version

* remove npm-shrinkwrap

* add npm-shrinkwrap.json to .gitignore

* 3.7.2

* HTTPS link to opensource.org/licenses/MIT (animate-css#943)

* Updated CDN version

* Added feedback request on README

* Updated formatting on README

* Remove `sudo npm` from instructions (animate-css#952)

Running `npm` as root has a lot of disadvantages (ref: https://medium.com/@ExplosionPills/dont-use-sudo-with-npm-still-66e609f5f92). Modern versions of npm allow running tools from `node_modules/.bin` by calling `npx`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants