Skip to content

Instantly share code, notes, and snippets.

@jwood
Last active March 15, 2021 16:03
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jwood/90e7bf6873774055b169 to your computer and use it in GitHub Desktop.
Save jwood/90e7bf6873774055b169 to your computer and use it in GitHub Desktop.
Disable animations
<!-- app/views/layouts/application.html.erb -->
<!DOCTYPE html>
<html lang="en">
<head>
<!-- ... -->
<% if Rails.application.config.disable_animations %>
<%= stylesheet_link_tag('disable_animations') %>
<!-- Turn off animations in jQuery -->
<script>$.fx.off = true;</script>
<% end %>
</head>
<body>
<!-- ... -->
</body>
</html>
# config/application.rb
module Urbanbound
class Application < Rails::Application
# ...
config.disable_animations = false
end
end
/* Disable animations, only for test environments.*/
* {
-webkit-transition: none !important;
-moz-transition: none !important;
-ms-transition: none !important;
-o-transition: none !important;
transition: none !important;
}
# config/environments/test.rb
Rails.application.configure do
# ...
config.disable_animations = true
end
@jersingh
Copy link

Had to add these extra transitions to get everything (bootstrap animations included) to disable:

transition-property: none !important;
 -o-transition-property: none !important;
 -moz-transition-property: none !important;
 -ms-transition-property: none !important;
 -webkit-transition-property: none !important;

 transform: none !important;
 -o-transform: none !important;
 -moz-transform: none !important;
 -ms-transform: none !important;
 -webkit-transform: none !important;

 animation: none !important;
 -o-animation: none !important;
 -moz-animation: none !important;
 -ms-animation: none !important;
 -webkit-animation: none !important;

@rokumatsumoto
Copy link

_disable_animations.html.haml

- if Rails.application.config.disable_animations
  = stylesheet_link_tag('disable_animations')
  / Turn off animations in jQuery
  :javascript
    $.fx.off = true;

config/initializers/assets.rb

Rails.application.config.assets.precompile += %w[disable_animations.scss] if Rails.env.test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment