php中如何滚动文字,如何实现单行文字向上滚动的效果(附代码)

这篇文章给大家介绍的内容是关于如何实现单行文字向上滚动的效果(附代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

最近在做一个活动页,需要一个单行文字向上滚动的效果来展示获奖公告。

效果如下:

40b3966fa73e986231ca263ef6a78958.gif

废话不多说,下面直接贴上代码。

html代码如下:

  • {{item.phone}}抽中{{item.prizeName}}
  • {{noticeList[0].phone}}抽中{{noticeList[0].prizeName}}
  • {{noticeList[0].phone}}抽中{{noticeList[0].prizeName}}
  • 获奖公告

less代码如下:.notice{

display: flex;

justify-content: center;

padding-bottom: .26rem;

img{

width: .3rem;

height: .24rem;

}

.wrap{

position: relative;

height:.3rem;

overflow: hidden;

margin-left: .15rem;

font-size: .24rem;

color: #391b03;

}

ul{

position: relative;

top: -.3rem;

li{

height: .3rem;

line-height: .3rem;

}

}

.transitionTop{

transition: top 200ms ease-in-out;

}

}

js代码如下:// data下

noticeTop: 0, // 公告top值

isActive:true, // 是否显示transitionTop动画

timer: null, // 公告滚动定时器

noticeList: [

{

phone:'135****1234',

prizeName:'50元还款券'

},

{

phone:'135****1234',

prizeName:'60元还款券'

},

{

phone:'135****1234',

prizeName:'70元还款券'

}

], // 公告列表

// computed下

noticeLen(){ // 公告列表长度

return this.noticeList.length;

}

//methods下

noticeScroll(){// 公告滚动,定时改变公告的top值

if(this.noticeLen > 0){

let index =1,

len = this.noticeLen === 1 ? 3 : (this.noticeLen + 1);

this.timer = setInterval(() => {

this.isActive = true;

this.noticeTop = -3 * index / 10;

index ++;

if(index === len){// 滚动到底部时返回

let delayTime = setTimeout(() => {

this.isActive = false;

this.noticeTop = 0;

index = 1;

clearTimeout(delayTime);

}, 1000);

}

}, 3000);

}

}

//调用

this.noticeScroll();

需要说明的是:

1.项目是基于vue的语法

2.滚动到底部返回时加了个延迟,是为了能滚动到最后一个,然后从最后一个返回到第一个。

相关文章推荐:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值