--- title: prefers-reduced-motion slug: Web/CSS/@media/prefers-reduced-motion translation_of: Web/CSS/@media/prefers-reduced-motion ---
CSS 媒体查询特性 prefers-reduced-motion
用于检测用户的系统是否被开启了动画减弱功能。
no-preference
reduce
在火狐中,满足以下条件则 reduce
会生效:
gtk-enable-animations
的值为 false
。
[Settings]
模块下设置 gtk-enable-animations = false
。下面的例子将会展示一组令人心烦的动画,不过当你开启了系统的“减少运动”后就能看到动画减弱的效果了。
<div class="animation">animated box</div>
.animation { animation: vibrate 0.3s linear infinite both; } @media (prefers-reduced-motion: reduce) { .animation { animation: none; } }
.animation { background-color: rebeccapurple; color: #fff; font: 1.2em Helvetica, arial, sans-serif; width: 200px; padding: 1em; border-radius: 1em; text-align: center; } /* ---------------------------------------------- * Generated by Animista on 2018-9-2 13:47:0 * w: http://animista.net, t: @cssanimista * ---------------------------------------------- */ /** * ---------------------------------------- * animation vibrate-1 * ---------------------------------------- */ @keyframes vibrate { 0% { transform: translate(0); } 20% { transform: translate(-2px, 2px); } 40% { transform: translate(-2px, -2px); } 60% { transform: translate(2px, 2px); } 80% { transform: translate(2px, -2px); } 100% { transform: translate(0); } }
{{EmbedLiveSample("例子")}}
Specification | Status | Comment |
---|---|---|
{{SpecName('CSS5 Media Queries', '#descdef-media-prefers-reduced-motion', 'prefers-reduced-motion')}} | {{Spec2('CSS5 Media Queries')}} | Initial definition. |
{{Compat("css.at-rules.media.prefers-reduced-motion")}}