css 文字版无限滚动动画(附源码)
<h2>样式效果</h2><p><img src="https://www.3bbs.cn/index-diy/img.php?url=https://mmbiz.qpic.cn/mmbiz_png/Ww5kqqWjHkgGtqoOicBrtBSSFYOlC0iaiacrdHR7Ja7JTk1DgcM0ibNGAibOnBxYH1sYOpumMzy1Kwxgec6WPibnfSnw/640?wx_fmt=png&from=appmsg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" alt="图片" /></p>
<h2>完整源码</h2>
<pre><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文字版无限滚动动画</title>
<style>
body {
font-family: "Montserrat", sans-serif;
background: #1e293b;
color: #f8fafc;
overflow: hidden;
}
.app {
min-width: 100vw;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
header {
display: flex;
flex-direction: column;
align-items: center;
margin: 1rem;
text-align: center;
}
header h1 {
font-weight: 600;
font-size: 2rem;
margin-bottom: 0.5rem;
}
@media (min-width: 768px) {
header h1 {
font-size: 3rem;
}
}
header p {
color: #94a3b8;
margin-bottom: 0.5rem;
}
header a {
color: #7393c1;
}
.tag-list {
width: 30rem;
max-width: 90vw;
display: flex;
flex-shrink: 0;
flex-direction: column;
gap: 1rem 0;
position: relative;
padding: 1.5rem 0;
overflow: hidden;
}
.loop-slider .inner {
display: flex;
width: fit-content;
animation-name: loop;
animation-timing-function: linear;
animation-iteration-count: infinite;
animation-direction: var(--direction);
animation-duration: var(--duration);
}
.tag {
display: flex;
align-items: center;
gap: 0 0.2rem;
color: #e2e8f0;
font-size: 0.9rem;
background-color: #334155;
border-radius: 0.4rem;
padding: 0.7rem 1rem;
margin-right: 1rem;
box-shadow: 0 0.1rem 0.2rem rgba(0, 0, 0, 0.2), 0 0.1rem 0.5rem rgba(0, 0, 0, 0.3), 0 0.2rem 1.5rem rgba(0, 0, 0, 0.4);
}
.tag span {
font-size: 1.2rem;
color: #64748b;
}
.fade {
pointer-events: none;
background: linear-gradient(90deg, #1e293b, transparent 30%, transparent 70%, #1e293b);
position: absolute;
inset: 0;
}
@keyframes loop {
0% {
transform: translateX(0);
}
100% {
transform: translateX(-50%);
}
}
</style>
</head>
<body>
<div class="app">
<div class="tag-list">
<div class="loop-slider" style="--duration:15951ms; --direction:normal;">
<div class="inner">
<div class="tag"><span>#</span> JavaScript</div>
<div class="tag"><span>#</span> HTML</div>
<div class="tag"><span>#</span> Typescript</div>
<div class="tag"><span>#</span> Node.js</div>
<div class="tag"><span>#</span> SVG</div>
<!-- 重复内容 循环-->
<div class="tag"><span>#</span> JavaScript</div>
<div class="tag"><span>#</span> HTML</div>
<div class="tag"><span>#</span> Typescript</div>
<div class="tag"><span>#</span> Node.js</div>
<div class="tag"><span>#</span> SVG</div>
</div>
</div>
<div class="loop-slider" style="--duration:16638ms; --direction:reverse;">
<div class="inner">
<div class="tag"><span>#</span> animation</div>
<div class="tag"><span>#</span> WebRTC</div>
<div class="tag"><span>#</span> CSS</div>
<div class="tag"><span>#</span> React</div>
<div class="tag"><span>#</span> Vue</div>
<!-- 重复内容 -->
<div class="tag"><span>#</span> animation</div>
<div class="tag"><span>#</span> WebRTC</div>
<div class="tag"><span>#</span> CSS</div>
<div class="tag"><span>#</span> React</div>
<div class="tag"><span>#</span> Vue</div>
</div>
</div>
<div class="fade"></div>
</div>
</div>
</body>
</html>
</code></pre>
页:
[1]