You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.5 KiB
68 lines
1.5 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>列表无限滚动</title>
|
|
</head>
|
|
<style>
|
|
.container {
|
|
position: relative;
|
|
background-color: #a4ffcc;
|
|
/* 父容器需要有明确的高度 */
|
|
height: 150px;
|
|
width: 200px;
|
|
margin: auto;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.container > .scroll-list {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
animation: scroll 6s linear infinite normal;
|
|
}
|
|
|
|
.container > .scroll-list > div {
|
|
width: 100%;
|
|
/* 滚动的项目需要有具体的高度 */
|
|
height: 30px;
|
|
background-color: #1ea7ff;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
color: white;
|
|
}
|
|
|
|
|
|
|
|
@keyframes scroll {
|
|
100% {
|
|
/* 需要滚动内容的总高度 */
|
|
top: -300px;
|
|
}
|
|
}
|
|
</style>
|
|
<body>
|
|
<div class="container">
|
|
<div class="scroll-list">
|
|
<div>1</div>
|
|
<div>2</div>
|
|
<div>3</div>
|
|
<div>4</div>
|
|
<div>5</div>
|
|
<div>6</div>
|
|
<div>7</div>
|
|
<div>8</div>
|
|
<div>9</div>
|
|
<div>10</div>
|
|
<!-- 下面代码是为了让滚动内容能够多展示一屏(去除留白/无限轮播):数量请自行根据高度进行计算 -->
|
|
<div>1</div>
|
|
<div>2</div>
|
|
<div>3</div>
|
|
<div>4</div>
|
|
<div>5</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|