@keyframes move {
0% {
transform: translateX(0);
}
100% {
transform: translateX(‘这里是跑马灯所有子元素+第一个子元素的宽度总和’);
}
}
例子:
<template>
<!-- 跑马灯 -->
<div class="data-count-box-animation">
<div class="animation-box">
<span
class="data-count-text-animation"
>
<slot></slot>
<slot></slot>
</span
>
</div>
</div>
</template>
<script lang="ts">
</script>
<style lang="scss" scoped>
.data-count-box-animation {
font-size: 0;
background: #025eff1a;
width:100%;
box-sizing: border-box;
padding: 0 4px;
gap: 0px;
height: 22px;
border-radius: 2px;
border: 0.5px solid #025eff;
margin-top: 12px;
white-space: nowrap;
overflow: hidden;
position: relative;
flex-shrink: 0;
}
.animation-box {
width: max-content;
left: 0;
position: absolute;
white-space: nowrap;
display: inline-flex;
height: 22px;
justify-content: space-between;
animation: marquee 18s linear infinite;
}
.data-count-text {
font-family: PingFang SC;
font-size: 10px;
font-weight: 400;
height: 22px !important;
line-height: 22px;
margin: 0;
color: #000000cc;
}
.data-count-text-animation {
display: inline-block;
font-family: PingFang SC;
font-size: 10px;
font-weight: 400;
line-height: 22px;
margin-right: 20px;
color: #000000cc;
}
// @keyframes marquee {
// 0% {
// transform: translateX(0%); /* 从右侧进入 */
// }
// 100% {
// transform: translateX(-100%); /* 向左移动到完全离开 */
// }
// }
@keyframes marquee {
0% {
transform: translateX(0%); /* 从右侧进入 */
}
100% {
transform: translateX(-50%); /* 向左移动到完全离开 */
}
}
</style>


