stylus中文版参考文档之关键帧(@keyframes)
回到相关文章 »文档:
- 选择器(Selectors)
- 变量(Variables)
- 插值(Interpolation)
- 运算符(Operators)
- 混合书写(Mixins)
- 方法(Functions)
- 关键字参数(Keyword Arguments)
- 内置方法(Built-in Functions)
- 其余参数(Rest Params)
- 注释(Comments)
- 条件(Conditionals)
- 迭代(Iteration)
- @import
- @media
- @font-face
- @keyframes
- @extend
- url()
- CSS字面量(CSS Literal)
- CSS样式解析(CSS Style Syntax)
- 字符转码(Char Escaping)
- 可执行性(Executable)
- 错误报告(Error Reporting)
- 连接中间件(Connect Middleware)
- 自检API(Introspection API)
- JavaScript API
- Nib下CSS扩展(CSS3 Extensions with Nib)
- Stylus在线体验!
详细:
关键帧(@keyframes)
@keyframes
Stylus支持@keyframes规则,当编译的时候转换成@-webkit-keyframes:
@keyframes pulse 0% background-color red opacity 1.0 -webkit-transform scale(1.0) rotate(0deg) 33% background-color blue opacity 0.75 -webkit-transform scale(1.1) rotate(-5deg) 67% background-color green opacity 0.5 -webkit-transform scale(1.1) rotate(5deg) 100% background-color red opacity 1.0 -webkit-transform scale(1.0) rotate(0deg)
生成为:
@-webkit-keyframes pulse {
0% {
background-color: red;
opacity: 1;
-webkit-transform: scale(1) rotate(0deg);
}
33% {
background-color: blue;
opacity: 0.75;
-webkit-transform: scale(1.1) rotate(-5deg);
}
67% {
background-color: green;
opacity: 0.5;
-webkit-transform: scale(1.1) rotate(5deg);
}
100% {
background-color: red;
opacity: 1;
-webkit-transform: scale(1) rotate(0deg);
}
}
扩展
使用@keyframes,通过vendors变量,会自动添加私有前缀(webkit moz official)。这意味着你可以子啊任意时候立即高效地做修改。
考虑下面的例子:
@keyframes foo {
from {
color: black
}
to {
color: white
}
}
扩增两个默认前缀,官方解析:
@-moz-keyframes foo {
0% {
color: #000;
}
100% {
color: #fff;
}
}
@-webkit-keyframes foo {
0% {
color: #000;
}
100% {
color: #fff;
}
}
@keyframes foo {
0% {
color: #000;
}
100% {
color: #fff;
}
}
如果我们只想有标准解析,很简单,修改vendors:
vendors = official
@keyframes foo {
from {
color: black
}
to {
color: white
}
}
生成为:
@keyframes foo {
0% {
color: #000;
}
100% {
color: #fff;
}
}