CSS animation动画和关键帧实现轮播图效果HTML
这轮播图效果使用h5和css3实现效果,不需要js控制,但是其中的缺点就是不能使用鼠标进行切换效果。
具有代码如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS animation动画和关键帧实现轮播图效果</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
#contianer {
width: 800px;
height: 500px;
overflow: hidden;
position: relative;
margin: 0 auto;
}
ul {
width: 4000px;
position: absolute;
animation: animationContent 10s infinite normal;
list-style: none;
}
li {
float: left;
position: relative;
}
li>img {
width: 800px;
height: 500px;
}
li .num {
position: absolute;
width: 80px;
height: 80px;
line-height: 80px;
background: rgba(136, 255, 0, 0.5);
border-radius: 50%;
text-align: center;
font-size: 30px;
color: rgba(255, 255, 255, 0.5);
font-weight: bold;
margin: 0 auto;
left: calc(50% - 40px);
top: calc(50% - 40px);
}
@keyframes animationContent {
0% {
left: 0;
}
25% {
left: -100%;
}
50% {
left: -200%;
}
75% {
left: -300%;
}
100% {
left: -400%;
}
}
</style>
</head>
<body>
<div id="contianer">
<ul>
<li>
<div class="num">1</div>
<img src="https://img0.baidu.com/it/u=1049144354,3589714554&fm=253&fmt=auto&app=120&f=JPEG?w=1280&h=800">
</li>
<li>
<div class="num">2</div>
<img src="https://img1.baidu.com/it/u=1168515712,1565504543&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500">
</li>
<li>
<div class="num">3</div>
<img src="https://img2.baidu.com/it/u=2080453877,3879502418&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=500">
</li>
<li>
<div class="num">4</div>
<img src="https://img1.baidu.com/it/u=1141047078,1542868282&fm=253&fmt=auto&app=120&f=JPEG?w=1280&h=800">
</li>
<li>
<div class="num">5</div>
<img src="https://img1.baidu.com/it/u=2337288053,330189716&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500">
</li>
</ul>
</div>
</body>
</html>