我是靠谱客的博主 背后老虎,这篇文章主要介绍vue实现消息的无缝滚动效果,现在分享给大家,希望可以做个参考。

<ul id="con1" ref="con1" :class="{anim:animate==true}">

复制代码
1
<li v-for='item in items'>{{item.name}}</li>

</ul>

<script>

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
export default { data() { return { animate:false, items:[ {name:"马云"}, {name:"雷军"}, {name:"王勤"} ] } }, created(){ setInterval(this.scroll,1000) }, methods: { scroll(){ this.animate=true; // 因为在消息向上滚动的时候需要添加css3过渡动画,所以这里需要设置true setTimeout(()=>{ // 这里直接使用了es6的箭头函数,省去了处理this指向偏移问题,代码也比之前简化了很多 this.items.push(this.items[0]); // 将数组的第一个元素添加到数组的 this.items.shift(); //删除数组的第一个元素 this.animate=false; // margin-top 为0 的时候取消过渡动画,实现无缝滚动 },500) } }

}
</script>

样式设置

<style>

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
*{ margin: 0 ; padding: 0; } #box{ width: 300px; height: 32px; overflow: hidden; padding-left: 30px; border: 1px solid black; } .anim{ transition: all 0.5s; margin-top: -30px; } #con1 li{ list-style: none; line-height: 30px; height: 30px; }

</style>

最后

以上就是背后老虎最近收集整理的关于vue实现消息的无缝滚动效果的全部内容,更多相关vue实现消息内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(110)

评论列表共有 0 条评论

立即
投稿
返回
顶部