让我首先说我是一名新手开发人员(甚至可能低于此),所以,如果我不能很好地解释自己,我会道歉。
我正在尝试获得有关我们产品的几个客户评论,以便在屏幕上显示(FadeIn1,延迟,FadeOut1),(FadeIn2,延迟,FadeOut2)等。我可以获得淡入和淡出以单独工作但我似乎无法让他们一起工作。以下代码仅淡出。有人可以让我知道我做错了什么吗?提前谢谢......
/* keyframes that tell the start state and the end state of our object */
@-webkit-keyframes fadeIn { from { opacity:0; } to { opacity:1; }}
@-moz-keyframes fadeIn { from { opacity:0; } to { opacity:1; }}
@keyframes fadeIn { from { opacity:0; } to { opacity:1; }}
@-webkit-keyframes fadeOut { from { opacity:1; } to { opacity:0; }}
@-moz-keyframes fadeOut { from { opacity:1; } to { opacity:0; }}
@keyframes fadeOut { from { opacity:1; } to { opacity:0; }}
.fade-in {
opacity:0; /* make things invisible upon start */
-webkit-animation:fadeIn ease-in 1; /* call keyframe named fadeIn, use animattion ease-in and repeat it only 1 time */
-moz-animation:fadeIn ease-in 1;
animation:fadeIn ease-in 1;
-webkit-animation-fill-mode:forwards; /* this makes sure that after animation is done we remain at the last keyframe value (opacity: 1)*/
-moz-animation-fill-mode:forwards;
animation-fill-mode:forwards;
-webkit-animation-duration:1s;
-moz-animation-duration:1s;
animation-duration:1s;
}
.fade-out {
opacity:1; /* make things visible upon start */
-webkit-animation:fadeOut ease-out 1; /* call keyframe named fadeOut, use animattion ease-out and repeat it only 1 time */
-moz-animation:fadeOut ease-out 1;
animation:fadeOut ease-out 1;
-webkit-animation-fill-mode:forwards; /* this makes sure that after animation is done we remain at the last keyframe value (opacity: 0)*/
-moz-animation-fill-mode:forwards;
animation-fill-mode:forwards;
-webkit-animation-duration:1s;
-moz-animation-duration:1s;
animation-duration:1s;
-webkit-animation-delay: 3s;
-moz-animation-delay: 3s;
animation-delay: 3s;
}
.fade-in.fade-out.one {
-webkit-animation-delay: 0.7s;
-moz-animation-delay: 0.7s;
animation-delay: 0.7s;
}
.fade-in.fade-out.two {
-webkit-animation-delay: 1.2s;
-moz-animation-delay:1.2s;
animation-delay: 1.2s;
}
.fade-in.fade-out.three {
-webkit-animation-delay: 1.6s;
-moz-animation-delay: 1.6s;
animation-delay: 1.6s;
}
/*---basic box ---*/
.box{
width: 200px;
height: 200px;
position: relative;
margin: 10px;
float: left;
border: 1px solid #333;
background: #999;
}
<body>
<div class="box fade-in fade-out one">
look at me fade in and out
</div>
<div class="box fade-in fade-out two">
i can fade too!
</div>
<div class="box fade-in fade-out three">
i can fade three!
</div>
</body>
答案 0 :(得分:0)
您可以使用%frames 简化动画。
您可以在.box
动画选择器下控制动画的速度。
@-webkit-keyframes myfade {
0% {
opacity: 0
}
20% {
opacity: 0
}
30% {
opacity: 1
}
40% {
opacity: 1
}
50% {
opacity: 1
}
60% {
opacity: 1
}
70% {
opacity: 0
}
80% {
opacity: 0
}
100% {
opacity: 0
}
}
@-moz-keyframes myfade {
0% {
opacity: 0
}
20% {
opacity: 0
}
30% {
opacity: 1
}
40% {
opacity: 1
}
50% {
opacity: 1
}
60% {
opacity: 1
}
70% {
opacity: 0
}
80% {
opacity: 0
}
100% {
opacity: 0
}
}
@keyframes myfade {
0% {
opacity: 0
}
20% {
opacity: 0
}
30% {
opacity: 1
}
40% {
opacity: 1
}
50% {
opacity: 1
}
60% {
opacity: 1
}
70% {
opacity: 0
}
80% {
opacity: 0
}
100% {
opacity: 0
}
}
.box {
width: 200px;
height: 200px;
position: relative;
margin: 10px;
float: left;
border: 1px solid #333;
background: #999;
animation: myfade 8s;
opacity: 0
}
<body>
<div class="box fade-in fade-out one">
look at me fade in and out
</div>
<div class="box fade-in fade-out two">
i can fade too!
</div>
<div class="box fade-in fade-out three">
i can fade three!
</div>
</body>
答案 1 :(得分:0)
您的原始代码非常接近。基于@ILoveCSS答案以及您对动画延迟的使用,我认为这是您正在寻找的效果:
@keyframes fade {
0% { opacity: 0 }
20% { opacity: 1 } /* 20% of 5 seconds = 1 second */
80% { opacity: 1 }
100% { opacity: 0 }
}
.fade {
opacity:0;
animation: fade ease-in-out 5s;
animation-fill-mode: forwards;
}
.fade:nth-child(2) { animation-delay: 0.25s; }
.fade:nth-child(3) { animation-delay: 0.5s; }
.box{
width: 100px;
height: 100px;
position: relative;
margin: 10px;
float: left;
border: 1px solid #333;
background: #999;
}
<div class="box fade">Box 1</div>
<div class="box fade">Box 2</div>
<div class="box fade">Box 3</div>