Vue transition-group 组件实现文字跑马灯效果

如下图所示,要求循环滚动一系列文本信息。

1
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<template>
<div class="carousel">
<div class="tube">
<transition-group name="list" tag="ul" class="tube_list">
<li v-for="(item , index) in executingList" :key="item + index" class="tube_list_item">
<div>{{ item.sentence }}</div>
</li>
</transition-group>
</div>
</div>
</template>

<style lang="scss" scoped>
.carousel {
color: #fff;
font-size: 24px;
width: 100%;
padding: 24px 24px 16px;
.tube {
position: relative;
color: #fff;
width: 572px;
height: 58px;
line-height: 58px;
border-radius: 29px;
background: #AB812A;
padding: 0 24px 0 8px;
overflow: hidden;
&_list {
width: 100%;
position: absolute;
bottom: 0;
&_item {
display: flex;
align-items: center;
img {
width: 40px;
height: 40px;
border-radius: 50%;
}
div {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
padding: 0 12px 0 16px;
}
}
}
}
}

.list-move {
transition: transform 1s;
}
.list-enter-active,
.list-leave-active {
transition: transform 1s linear, opacity 1s ease;
}
.list-enter-from {
opacity: 0;
transform: translateY(50%);
}
.list-leave-to {
opacity: 0;
transform: translateY(-50%);
}
</style>

文字跑马灯

参考文献

列表过渡 | Vue.js (vuejs.org)