0
我试图在3张图像之间使用css进行交叉淡入淡出。多个图像之间的淡入淡出CSS
我是@keyframes的新手,所以即时通讯有麻烦让它工作。
下面,是HTML和CSS代码片段:
的index.html:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="cf">
<img class="bottom" src="assets/1.png" />
<img class="top" src="assets/2.png" />
<img class="bottom" src="assets/3.png">
</div>
</body>
</html>
的style.css:
#cf {
position: relative;
height: auto;
width: auto;
margin: 0 auto;
}
#cf img {
position: absolute;
left: 0;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
#cf img {
animation-name: cf3FadeInOut;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-duration: 6s;
animation-direction: alternate;
}
#cf img:nth-of-type(1) {
animation-delay: 4s;
}
#cf img:nth-of-type(2) {
animation-delay: 2s;
}
#cf img:nth-of-type(3) {
animation-delay: 0;
}
@keyframes cf3FadeInOut {
0% {
opacity: 1;
}
17% {
opacity: 1;
}
25% {
opacity: 0;
}
92% {
opacity: 0;
}
100% {
opacity: 1;
}
}
眼下,动画怪怪的,从闪烁一个图像到另一个,随机动画时间。
工作正常!如何增加img转换之间的时间?他们转得很快。 – GreetingsFriend
只需更改时间 - 我将其添加到相应的答案中。 – Christoph
有时会显示背景低音图像。我可以让它停止吗? – GreetingsFriend