vue实现简单跑马灯效果

时间:2021-05-26

本文实例为大家分享了vue实现简单跑马灯效果的具体代码,供大家参考,具体内容如下

如下图片,会自行向上“滚动”

代码:

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>跑马灯 </title> <script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.min.js"></script> <style> div, ul, li, img { margin: 0; padding: 0; box-sizing: border-box; display: flex; } .horseLamp { width: 100%; height: 50px; align-items: center; background-color: #ddd; display: flex; box-sizing: border-box; } .horseLamp_box { display: block; position: relative; width: 60%; height: 30px; overflow: hidden; } .horseLamp_list { display: block; position: absolute; top: 0; left: 0; } .horseLamp_top { transition: all 0.2s; margin-top: -30px } .horseLamp_list li { height: 30px; line-height: 30px; font-size: 14px; } </style> </head><body> <div class="vueBox"> <div class="horseLamp"> <div class="horseLamp_box"> <ul class="horseLamp_list" :class="{horseLamp_top:animate}"> <li v-for="(item, index) in horseLampList"> <img :src="item.img"> </li> </ul> </div> </div></div> <script type="text/javascript"> const vm = new Vue ({ el: ".vueBox", data: { animate: false, horseLampList: [ { img:'../assets/logo.png' }, { img:'../assets/logo.png' }, { img:'../assets/logo.png' }, { img:'../assets/logo.png' } ] }, created: function () { setInterval (this.showhorseLamp, 600) }, methods: { showhorseLamp: function () { this.animate = true; setTimeout (() => { this.horseLampList.push (this.horseLampList[ 0 ]); this.horseLampList.shift (); this.animate = false; }, 2000); } } });</script> </body></html>

更多文章可以点击《Vue.js前端组件学习教程》学习阅读。

关于vue.js组件的教程,请大家点击专题vue.js组件学习教程进行学习。

更多vue学习教程请阅读专题《vue实战教程》

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章