.slider{
width: 890px;
height: 400px;
background: url(1.png);
margin: 100px auto;
animation-name: slide;
animation-duration: 10s;
animation-delay: 0s;
animation-iteration-count: infinite;
animation-timing-function: ease-in-out;
animation-direction: normal;
animation-fill-mode: forwards;
@keyframes slide{
25%{
background: url(2.png);
}
50%{
background: url(3.jpg);
}
75%{
background: url(4.png);
}
100%{
background: url(1.png);
}
上面是一个div框的css,我想在其中放置一些自动图像幻灯片。只是阅读了有关CSS动画的信息,但是当我尝试实现CSS动画时,什么都没有发生,有人可以请我帮我弄错我的地方,并且可以就我正在尝试的同一概念提供一个简单的示例,这将对我有很大的帮助< / p>
答案 0 :(得分:0)
如果您使用的代码与上述代码完全相同,则会出错。
请在下面找到更正的完整代码:
<!doctype html>
<html lang="en">
<head>
<title>Pure CSS Slider</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="author" content="https://akashshivanand.com">
<style>
.slider {
width: 890px;
height: 400px;
background: url("http://lorempixel.com/890/400/sports");
margin: 100px auto;
animation-name: slide;
animation-duration: 10s;
animation-iteration-count: infinite;
animation-timing-function: ease-in-out;
animation-direction: normal;
animation-fill-mode: forwards;
}
@keyframes slide {
25% {
background: url(http://lorempixel.com/890/400/sports/1);
}
50% {
background: url(http://lorempixel.com/890/400/sports/2);
}
75% {
background: url(http://lorempixel.com/890/400/sports/3);
}
100% {
background: url(http://lorempixel.com/890/400/sports/4);
}
}
</style>
</head>
<body>
<div class="slider"></div>
</body>
</html>