<template>
<div >
<ul class="list">
<li
v-for="(item, index) in gonghao"
:key="item.id"
:class="!index && tuo ? 'news' : ''"
>
{{ item.msg }}
</li>
</ul>
</div>
</template>
<script>
export default {
mounted() {
setInterval(this.start, 2000)
},
data() {
return {
gonghao: [
{ msg: '这是第一条信息' },
{ msg: '这是第二条信息' },
{ msg: '这是第三条信息' },
{ msg: '这是第四条信息' },
{ msg: '这是第五条信息' },
{ msg: '这是第六条信息' },
{ msg: '这是第七条信息' },
{ msg: '这是第八条信息' },
{ msg: '这是第九条信息' },
{ msg: '这是第十条信息' }
],
tuo: false
}
},
methods: {
start() {
let that = this
that.tuo = true //开始播放
setTimeout(() => {
that.gonghao.push(that.gonghao[0]) //将第一条数据塞到最后一个
that.gonghao.shift() //删除第一条数据
that.tuo = false //暂停播放,此处修改,保证每一次都会有动画显示
}, 500)
}
}
}
</script>
<style lang="less" scoped>
.news {
margin-top: -40px;
transition: all 0.5s;
}
.title {
width: 40px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
cursor: pointer;
}
.list {
list-style: none;
width: 200px;
text-align: center;
overflow: hidden;
height: 120px;
padding: 0;
margin: 0;
}
li {
text-align: left;
height: 40px;
line-height: 40px;
}
</style>