这篇文章主要讲解了vue实现简单跑马灯的方法,内容清晰明了,对此有兴趣的小伙伴可以学习一下,相信大家阅读完之后会有帮助。
本文实例为大家分享了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实现简单跑马灯的方法有进一步的了解,如果还想学习更多内容,欢迎关注亿速云行业资讯频道。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。