vue 文字向上滚动

<template>
<view>
跑马灯效果

//uniapp  代码


<view class="box">
<view class="" :class="{anim:animate==true}" >
<view class="item" v-for='(item,index) in items' :key='index'>{{item.name}}</view>
</view>
</view>

//vue 代码

<div id="box">
            <ul id="con1" ref="con1" :class="{anim:animate==true}">
                <li v-for='item in items'>{{item.name}}</li>
            </ul>
        </div>



</view>
</template>

<script>
export default {
name:"marquee",
onReady() {
setInterval(this.scroll,3000)
},
data() {
return {
animate:false,
items:[
{ name: '1' },
{ name: '2' },
{ name: '3' },
{ name: '4' },
{ name: '5' },
]
};
},
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 lang="scss" scoped>

//uniapp 样式

.box{
width: 300px;
height: 32px;
overflow: hidden;
padding-left: 30px;
border: 1px solid black;
.item{
list-style: none;
line-height: 30px;
height: 30px;
}
}
.anim{
transition: all 0.5s;
margin-top: -30px;
}

 //  vue样式

#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>

posted @   shez  阅读(524)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示