只是好奇地想知道为什么这个简单的动画延迟似乎无法工作。我只想在元素淡入之前延迟7s。很简单,我确定,但已经看了很久了。
.box1 {
width: 100px;
margin: 0 auto;
position: relative;
border: 1px solid blue;
}
.box2 {
background: red;
color: black;
text-align: center;
animation-delay: 7s;
-webkit-animation-delay: 7s;
animation: fadein 2s linear;
-webkit-animation: fadein 2s linear;
}
@keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@-webkit-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}<div class= "box1">
<div class="box2">
<p>some text</p>
</div>
</div>
发布于 2017-01-10 21:53:16
尝试使用长格式animation属性:
animation-delayanimation-nameanimation-durationanimation-timing-function
.box1 {
width: 100px;
margin: 0 auto;
position: relative;
border: 1px solid blue;
}
.box2 {
background: red;
color: black;
text-align: center;
opacity: 0;
-webkit-animation-delay: 7s;
-webkit-animation-name: fadein;
-webkit-animation-duration: 2s;
-webkit-animation-timing-function: linear;
animation-delay: 7s;
animation-name: fadein;
animation-duration: 2s;
animation-timing-function: linear;
}
@-webkit-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}<div class= "box1">
<div class="box2">
<p>some text</p>
</div>
</div>
发布于 2017-01-10 21:48:02
将动画延迟放在动画之后,因为延迟需要附加到所讨论的动画(顺序很重要):
.box1 {
width: 100px;
margin: 0 auto;
position: relative;
border: 1px solid blue;
}
.box2 {
background: red;
color: black;
text-align: center;
-webkit-animation: fadein 2s linear;
animation: fadein 2s linear;
-webkit-animation-delay: 7s;
animation-delay: 7s;
}
@keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@-webkit-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}<div class="box1">
<div class="box2">
<p>some text</p>
</div>
</div>
或者使用速记方式,删除animation-delay: 7s;和-webkit-animation-delay: 7s;,并将延迟时间添加到animation属性中,如下所示:
-webkit-animation:fadein 2s linear 7s;
animation:fadein 2s linear 7s;
.box1 {
width: 100px;
margin: 0 auto;
position: relative;
border: 1px solid blue;
}
.box2 {
background: red;
color: black;
text-align: center;
-webkit-animation: fadein 2s linear 7s;
animation: fadein 2s linear 7s;
}
@keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@-webkit-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}<div class="box1">
<div class="box2">
<p>some text</p>
</div>
</div>
发布于 2017-01-10 22:01:08
下面的代码工作,我将框的初始不透明度设置为0,这样它就“消失了”,而且只有在动画本身之后声明它时,动画延迟属性才能工作。我还添加了动画-填充模式:转发;以保持框后显示动画。
.box1 {
width: 100px;
margin: 0 auto;
position: relative;
border: 1px solid blue;
}
.box2 {
background: red;
color: black;
text-align: center;
animation: fadein 2s linear;
-webkit-animation: fadein 2s linear;
animation-delay: 7s;
-webkit-animation-delay: 7s;
animation-fill-mode: forwards;
-webkit-animation-fill-mode: forwards;
opacity: 0;
}
@keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@-webkit-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}<div class= "box1">
<div class="box2">
<p>some text</p>
</div>
</div>
https://stackoverflow.com/questions/41578922
复制相似问题