简体   繁体   English

禁用javascript时阻止CSS动画?

[英]Prevent CSS animation when javascript is disabled?

Is there some CSS that I can add inside a <noscript> that will prevent animations on a certain element when scripts are disabled? 是否可以在<noscript>中添加一些CSS,以在禁用脚本时阻止某些元素上的动画?

In other words, I want to prevent CSS3 animations on a certain class when scripts are disabled. 换句话说,当脚本被禁用时,我想防止某个类的CSS3动画。

What you can do is set a class when JavaScript is enabled . 可以做的是在启用 JavaScript时设置一个类。 Make sure all the animations look at that class. 确保所有动画都针对该类。

With JS you can add a class to your body tag, something like .js-enabled; 使用JS,您可以在body标签中添加一个类,例如.js-enabled; in your css scope the animations with that specific class. 在你的css范围内,该特定类的动画。

I've had a similar problem recently. 我最近遇到过类似的问题。 The easiest way is to assign a class on load . 最简单的方法是在加载时分配一个类。 That is your initial state then, and the state you want something to transition to is either the state without the class (when, for example, you want to reveal stuff) or yet another class. 那是你的初始状态,你希望转换到的状态是没有类的状态(例如,当你想要揭示东西时)或另一个类。 Or, if you're using a looped animation, then of course you don't have to worry about that and just assign animations to a class. 或者,如果您使用的是循环动画,那么您当然不必担心,只需将动画分配给类即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM