【发布时间】:2018-11-19 12:54:21
【问题描述】:
我有以下HMTL 和CSS:
.parent{
height: 10%;
width: 100%;
float: left;
}
.content1{
height: 100%;
width: 20%;
background-color: blue;
float: left;
}
.content2{
height: 100%;
width: 20%;
background-color: red;
float: left;
}
.content3{
height: 100%;
width: 20%;
background-color:yellow;
float: left;
}
.content4{
height: 100%;
width: 20%;
background-color: green;
float: left;
}
.content5{
height: 100%;
width: 20%;
background-color: orange;
float: left;
}
.parent {
animation-name: animation_01;
animation-duration:5s;
animation-iteration-count:1;
animation-fill-mode: forwards;
}
@keyframes animation_01 {
0% {
opacity: 0
}
20% {
opacity: 1
}
40% {
opacity: 0
}
60% {
opacity: 1
}
80% {
opacity: 0
}
100% {
opacity: 1
}
}
}
<div class="parent">
<div class="content1">Here goes content1</div>
<div class="content2">Here goes content2</div>
<div class="content3">Here goes content3</div>
<div class="content4">Here goes content4</div>
<div class="content5">Here goes content5</div>
</div>
此代码本身可以正常工作。
您也可以在 JSfiddle here 中找到它。
我现在的目标是一个接一个地显示content1 到content5。因此,我想在 CSS 的 animation 中使用 opacity 函数。但是,我还不知道如何将opacity 用于单个内容,因为现在动画只针对所有五个内容组合运行。
你知道是否有可能让这个动画在@keyframes 中工作,还是我需要像示例here 中那样的javascript/jQuery?
【问题讨论】:
-
那么,要先显示content1,隐藏content1。然后显示 content2,隐藏 content2,等等?
-
这正是我想要的。
-
查看@Itay Gal 的回答。
标签: html css css-animations keyframe