原理
demo代码
html1
2
3
4
5
6
7
8<div class="wrap">
<div class="slide-dom">
<div class="itemA">A</div>
<div class="itemB">B</div>
<div class="itemA">A</div>
<div class="itemB">B</div>
</div>
</div>
css1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36@keyframes infinite-slide {
0% {
transform: translateX(0);
}
100% {
transform: translateX(-50%);
}
}
.wrap{
overflow-x: visible;
background:#eee;
width:200px;
height:300px;
margin:0 auto;
padding:100px 0;
}
.slide-dom{
width:max-content;
animation: infinite-slide 10s linear infinite;
}
/* 鼠标悬浮时暂停动画 */
.slide-dom:hover{
animation-play-state: paused;
}
.itemA{
display:inline-block;
width:200px;
height:100px;
background:pink;
}
.itemB{
display:inline-block;
width:200px;
height:100px;
background:yellow;
}