Eri*_*oma 306 css animation css3 css-transitions
这是一个非常直截了当的问题,但我找不到关于CSS过渡属性的非常好的文档.这是CSS片段:
.nav a
{
text-transform:uppercase;
text-decoration:none;
color:#d3d3d3;
line-height:1.5 em;
font-size:.8em;
display:block;
text-align:center;
text-shadow: 0 -1.5em 0 rgba(255, 255, 255, 0.15);
-webkit-transition: color .2s linear;
-moz-transition: color .2s linear;
-o-transition: color .2s linear;
transition: color .2s linear;
-webkit-transition: text-shadow .2s linear;
-moz-transition: text-shadow .2s linear;
-o-transition: text-shadow .2s linear;
transition: text-shadow .2s linear;
}
.nav a:hover
{
color:#F7931E;
text-shadow: 0 1.5em 0 rgba(247, 147, 30, 0.15);
}
Run Code Online (Sandbox Code Playgroud)
如您所见,过渡属性会相互覆盖.就目前而言,文本阴影将动画,但不是颜色.我怎样让他们同时动画?谢谢你的回答.
cor*_*ard 538
在支持转换的所有浏览器中,转换属性以逗号分隔:
.nav a {
transition: color .2s, text-shadow .2s;
}
Run Code Online (Sandbox Code Playgroud)
ease是默认的计时功能,因此您不必指定它.如果你真的想要linear,你需要指定它:
transition: color .2s linear, text-shadow .2s linear;
Run Code Online (Sandbox Code Playgroud)
这开始变得重复,所以如果你要在多个属性中使用相同的时间和计时功能,最好继续使用各种transition-*属性而不是速记:
transition-property: color, text-shadow;
transition-duration: .2s;
transition-timing-function: linear;
Run Code Online (Sandbox Code Playgroud)
XML*_*XML 36
您还可以简单地使用:
.nav a {
-webkit-transition: all .2s;
}
Run Code Online (Sandbox Code Playgroud)
Del*_*ani 29
类似下面的内容将同时允许多个转换:
-webkit-transition: color .2s linear, text-shadow .2s linear;
-moz-transition: color .2s linear, text-shadow .2s linear;
-o-transition: color .2s linear, text-shadow .2s linear;
transition: color .2s linear, text-shadow .2s linear;
Run Code Online (Sandbox Code Playgroud)
Cor*_*ung 24
如果您将所有属性设置为相同的动画,则可以单独设置每个属性,这样您就不会重复代码.
transition: all 2s;
transition-property: color, text-shadow;
Run Code Online (Sandbox Code Playgroud)
这里有更多关于它的内容:CSS过渡速记有多个属性?
我会避免使用all属性(transition-property覆盖'all'),因为你可能会遇到不需要的行为和意外的性能命中.