jquery - 按需使用 CSS3 旋转元素

标签 jquery class css animation keyframe

我定义了这个关键帧:

@-moz-keyframes rotate{
    0%{
        -moz-transform: rotate(0deg);   
    }
    100%{
        -moz-transform: rotate(359deg);
    }
}

并应用于类名:

.rotate{
    -moz-animation-iteration-count: infinite;
    -moz-animation-timing-function: linear;
    -moz-animation-name: rotate;
}

并按需将类添加到元素中:

$('a').click(function(){ $(this).addClass('rotate'); });   /* and the class is applied */

但是元素不会旋转;我做错了什么?

请注意:我只在 firefox 中进行测试,这就是为什么我只使用 -moz- 供应商前缀

最佳答案

添加持续时间:

.rotate{
  -moz-animation-iteration-count: infinite;
  -moz-animation-timing-function: linear;
  -moz-animation-name: rotate;
  -moz-animation-duration: 1s;
}

持续时间定义了每次旋转需要多长时间。如果你不设置一个,the default is zero .

关于jquery - 按需使用 CSS3 旋转元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17550254/

相关文章:

jquery - 如何使用 jquery 和 css 制作像 Tabs 和 Pills 这样的 Bootstrap

javascript - 无法为每个输入字段提交右键[单个表单中的多个按钮和输入字段]

javascript - 在下拉列表中获取不可见的值

jquery - 第二次访问页面时未应用 Rails css/js

javascript - 如何更改粘性标题的背景

java - JTextPane 中未呈现 CSS 填充

c# - ASP.NET 和 C# : hide spinning wheel when button has finished processing

c++ - 从基类指针调用 C++ 中的私有(private)函数

php - 在类中使用全局函数是不好的做法吗?

java - 在java中检索具有Predicate返回类型的方法的值