当前位置: 首页 > Web前端 > CSS

单行文字向上滚动

时间:2023-03-30 14:02:11 CSS

最近在做一个活动页面,需要一个单行文字向上滚动的效果来展示获奖公告。效果如下:废话不多说,直接贴下面代码。html代码如下:{{item.phone}}绘制{{物品。prizeName}}0">{{noticeList[0].phone}}赢得{{noticeList[0].prizeName}}{{noticeList[0].phone}}抽取{{noticeList[0].prizeName}}获奖通知

less代码如下:.notice{display:flex;证明内容:居中;底部填充:.26rem;img{宽度:.3rem;高度:.24rem;}.wrap{位置:相对;高度:.3rem;溢出:隐藏;左边距:.15rem;字体大小:.24rem;颜色:#391b03;顶部:-.3rem;li{身高:.3rem;行高:.3rem;}}.transitionTop{transition:top200msease-in-out;}}js代码如下://noticeTopunderdata:0,//公告置顶值isActive:true,//是否显示transitionTop动画timer:null,//公告滚动定时器noticeList:[{phone:'135****1234',prizeName:'50元还款券'},{phone:'135****1234',prizeName:'60元还款券'},{phone:'135****1234',prizeName:'70元还款券'}],//公告列表//noticeLen()undercomputed{//公告列表长度returnthis.noticeList.length;}//noticeScroll()undermethods{//通知滚动,定时改变通知的top值if(this.noticeLen>0){letindex=1,len=this.noticeLen===1?3:(this.noticeLen+1);这。timer=setInterval(()=>{this.isActive=true;this.noticeTop=-3*index/10;index++;if(index===len){//滚动到底部时返回letdelayTime=setTimeout(()=>{this.isActive=false;这.noticeTop=0;索引=1;清除超时(延迟时间);},1000);}},3000);}}//调用this.noticeScroll();需要说明的是:1.项目是基于vue2的语法,在滚动到底部的时候加了一个延迟返回到最后一个,然后从最后一个返回到第一个