由于是全用的一张图,所以这个留白及卡顿问题没那么明显,
当时写的时候用了其他照片,还是会有一些卡顿
添加了一个hover,鼠标悬停轮播图会停止
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
width: 600px;
height: 150px;
border: 10px solid #000;
margin: 200px auto;
overflow: hidden;
}
.box:hover .banner {
/* 暂停图片动画 */
animation-play-state: paused;
}
.box .banner {
width: 2000px;
/* 2.调用动画 */
animation: move 5s linear infinite;
}
.box img {
cursor: pointer;
float: left;
width: 200px;
height: 150px;
}
/*1.定义 轮播图动画 */
@keyframes move {
0% {
transform: translate(0, 0);
}
100% {
transform: translate(-1400px, 0);
}
}
</style>
</head>
<body>
<div class="box">
<div class="banner">
<img src="./images/5.jpg" alt="">
<img src="./images/5.jpg" alt="">
<img src="./images/5.jpg" alt="">
<img src="./images/5.jpg" alt="">
<img src="./images/5.jpg" alt="">
<img src="./images/5.jpg" alt="">
<img src="./images/5.jpg" alt="">
<!-- 解决流白问题,补的图片是前面几张图片 -->
<img src="./images/5.jpg" alt="">
<img src="./images/5.jpg" alt="">
<img src="./images/5.jpg" alt="">
</div>
</div>
</body>
</html>