【发布时间】:2017-11-14 02:37:41
【问题描述】:
是否可以使用CSS 为元素设置动画,但不定义元素CSS 属性的初始状态?
在某些情况下它似乎有效 - 例如,如果我将不透明度设置为 0
.class{
transition : all 1s ease-out;
}
.class-after{
opacity : 0 // this works even without setting the initial opacity to 1
}
但是...当尝试为上、左、下、右属性设置动画时,如果不预设属性值,我似乎无法实现动画
.class{
transition : all 1s ease-out;
}
.class-after{
top : 100px; // this doesn't work without .class-before
}
.class-before{
position : relative;
top: 0px; // setting the initial value will cause it to work
}
预设属性值是必须的吗?哪些属性需要预设,哪些可以自发设置动画?
【问题讨论】:
-
默认
opacity : 1 -
是的,您不能从
auto值转换。left、right等默认为auto,您无法对其进行转换。opacity默认是1,所以不用初始设置就可以转换。