【发布时间】:2020-12-22 17:30:31
【问题描述】:
我试图让 div 在页面加载时一个接一个地出现。问题是这个设置只有在我向 div 选择器添加 visibility: hidden 属性时才有效,这反过来又会反转动画。我错过了什么?
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
display: flex;
align-items: center;
justify-content: space-around;
height: 100vh;
background-color: rgb(73, 73, 73);
}
div {
width: 15vh;
height: 15vh;
background-color: rgb(53, 53, 53);
}
.box1 {
animation: test 1s;
}
.box2 {
animation: test 1.1s;
}
.box3 {
animation: test 1.2s;
}
.box4 {
animation: test 1.3s;
}
.box5 {
animation: test 1.4s;
}
@keyframes test {
from {
visibility: hidden;
}
to {
visibility: visible;
}
}
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
<div class="box5"></div>
【问题讨论】:
-
visibility无法设置动画。更改为opacity: 0和opacity: 1,你的动画就可以正常工作了。 -
@Turnip 这不是我想要的工作方式。我不希望它淡入,而是弹出。
-
正如@Turnip 所说,使用
visibility以这种方式对其进行动画处理是不可能的。见stackoverflow.com/questions/27900053/…