纯css实现文字滚动
横向滚动示例
html
<div class="marquee">
<div class="marquee-wrap" style="width: 430px;text-align: center">
<span
class="yellow marquee-content">这是一断横向滚动的文字</span>
</div>
</div>
css
.marquee {
overflow: hidden;
}
.marquee .marquee-wrap {
width: 100%;
animation: marquee-wrap 4s infinite linear;
}
.marquee .marquee-content {
float: left;
white-space: nowrap;
min-width: 100%;
animation: marquee-content 4s infinite linear;
}
@keyframes marquee-wrap {
0%,
30% {
transform: translateX(0);
}
70%,
100% {
transform: translateX(100%);
}
}
@keyframes marquee-content {
0%,
30% {
transform: translateX(0);
}
70%,
100% {
transform: translateX(-100%);
}
}
实现效果
纵向滚动示例
html
<div class="marquee-y">
<div class="marquee-wrap-y" style="height: 330px;width:2360px;text-align: center">
<span class="marquee-content-y"><mark class="zyyjxx-index">{{index+1}} 、</mark>{{item}}</span>
</div>
</div>
css
.marquee-y {
overflow: hidden;
}
.marquee-y .marquee-wrap-y {
height: 100%;
animation: marquee-wrap-y 4s infinite linear;
}
.marquee-y .marquee-content-y {
float: left;
min-height: 100%;
max-width: 100%;
white-space: pre-wrap;
animation: marquee-content-y 4s infinite linear;
}
@keyframes marquee-wrap-y {
0%,
30% {
transform: translateY(0);
}
70%,
100% {
transform: translateY(100%);
}
}
@keyframes marquee-content-y {
0%,
30% {
transform: translateY(0);
}
70%,
100% {
transform: translateY(-100%);
}
}
实现效果
末尾停顿
因为滚动部分时间固定,可以设置80%的时间时滚动到100%,这样剩下20%的时间将会停顿在末尾
示例
/* 纵向滚动 */
.marquee-y {
overflow: hidden;
}
.marquee-y .marquee-wrap-y {
height: 100%;
animation: marquee-wrap-y infinite linear;
}
.marquee-y .marquee-content-y {
float: left;
min-height: 100%;
max-width: 100%;
white-space: pre-wrap;
animation: marquee-content-y infinite linear;
}
@keyframes marquee-wrap-y {
0% {
transform: translateY(0);
}
20% {
transform: translateY(25%);
}
40% {
transform: translateY(50%);
}
60% {
transform: translateY(75%);
}
80% {
transform: translateY(100%);
}
100% {
transform: translateY(100%);
}
}
@keyframes marquee-content-y {
0% {
transform: translateY(0);
}
20% {
transform: translateY(-25%);
}
40% {
transform: translateY(-50%);
}
60% {
transform: translateY(-75%);
}
80% {
transform: translateY(-100%);
}
100% {
transform: translateY(-100%);
}
}
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 ALLBS!
评论