One: target
Realize the effect of revolving door, and play the pictures seamlessly
Two: Realize ideas
1. Write a box first, with a width and a height border (note that the width of the box here cannot be scribbled, it should just fit an integer number of pictures)
2. ul>li>a to add pictures, then float and fine-tune to make the pictures line up, and hide the parts beyond the box (note: ul>li>a need to add a few more pictures, how many pictures to add depends on how many pictures can full box)
3. Add animation to ul, using transform: translateX(); property to achieve
4. Use the animation-play-state: paused; attribute to achieve the effect that the animation pauses when the mouse moves to the box
Three: complete code
<!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>
*{
margin: 0;
padding: 0;
}
li{
list-style: none;
}
.box{
width: 600px;
height: 112px;
border: 5px solid black;
margin: 100px auto;
overflow: hidden;
}
.box li img{
width: 200px;
}
/* 让图片都能横着排在一行 */
.box ul{
width: 2000px;
animation: move 5s infinite linear;
}
.box li {
float: left;
}
/* 图片向左移动的动画 */
@keyframes move{
to{
transform: translateX(-1400px);
}
}
/* 实现鼠标hover就暂停动画 */
/* 移动到hover就暂停,因为动画加在ul上所以ul变 */
.box:hover ul{
animation-play-state: paused;
}
</style>
</head>
<body>
<div class="box">
<ul>
<li><a href="#"><img src="./1.jpg"></a></li>
<li><a href="#"><img src="./2.jpg"></a></li>
<li><a href="#"><img src="./3.jpg"></a></li>
<li><a href="#"><img src="./4.jpg"></a></li>
<li><a href="#"><img src="./5.jpg"></a></li>
<li><a href="#"><img src="./6.jpg"></a></li>
<li><a href="#"><img src="./7.jpg"></a></li>
<!-- 前三张图片刚好把盒子的空填满 -->
<li><a href="#"><img src="./1.jpg"></a></li>
<li><a href="#"><img src="./2.jpg"></a></li>
<li><a href="#"><img src="./3.jpg"></a></li>
</ul>
</div>
</body>
</html>