【发布时间】:2012-08-02 11:40:35
【问题描述】:
我正在尝试使用 CSS 动画和转换来制作加载器 gif。不幸的是,以下代码将我的 Mac OSX 上的 Firefox(有时还有 Chrome、Safari)的 CPU 使用率从 90%。
i.icon-repeat {
display:none;
-webkit-animation: Rotate 1s infinite linear;
-moz-animation: Rotate 1s infinite linear; //**this is the offending line**
animation: Rotate 1s infinite linear;
}
@-webkit-keyframes Rotate {
from {-webkit-transform:rotate(0deg);}
to {-webkit-transform:rotate(360deg);}
}
@-keyframes Rotate {
from {transform:rotate(0deg);}
to {transform:rotate(360deg);}
}
@-moz-keyframes Rotate {
from {-moz-transform:rotate(0deg);}
to {-moz-transform:rotate(360deg);}
}
请注意,如果没有infinite linear 旋转或-moz- 供应商前缀,“loader gif”-like 行为就会丢失。也就是说,图标不会连续旋转。
也许这只是一个错误,或者我做错了什么?
【问题讨论】:
-
旁注:我知道这很常见,但是(Ab)使用
i作为图标确实是不好的做法,你不应该这样做。除此之外,我认为您无能为力,因为您的代码是正确的,而且我看不到其他方法。 -
出于好奇,为什么每个@keyframes 上都有opera 前缀? (我对他们没有经验,这是必需的吗?)
-
为什么不直接使用 spin.js 而不是从字面上重新发明(旋转)轮子?
-
@Christoph
i图标是 Twitter Bootstrap 语法,所以不幸的是,它可能变得相当普遍。我知道它会阻止 italics 字体标签,但还有其他 CSS 解决方案... -
@Cyrille 我想使用我自己的微调器图标。不知道 spin.js 是否允许这样做?
标签: css twitter-bootstrap css-transforms css-animations vendor-prefix