博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
单行文字向上滚动
阅读量:7074 次
发布时间:2019-06-28

本文共 1868 字,大约阅读时间需要 6 分钟。

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

图片描述

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

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.滚动到底部返回时加了个延迟,是为了能滚动到最后一个,然后从最后一个返回到第一个。

转载地址:http://rqkml.baihongyu.com/

你可能感兴趣的文章
PowerShell应用之-批量执行SQL脚本
查看>>
职场加薪步步高升的五大法则
查看>>
增删主键及修改表名
查看>>
Gson库使用-排序字段(ExclusionStrategy)或者修改(FieldNamingStrategy)字段
查看>>
NTFS For Mac 的特点有哪些
查看>>
新技能,利用Reflector来修改dll引用
查看>>
Java编程的逻辑 (1) - 数据和变量
查看>>
我的屌丝giser成长记-研一篇(下)
查看>>
raft 分布式协议 -- mongodb
查看>>
[TypeScript] Using Lodash in TypeScript with Typings and SystemJS
查看>>
ASP.Net MVC开发基础学习笔记(1):走向MVC模式
查看>>
虚函数可不可以是内联函数
查看>>
据说看完这21个故事的人,30岁前都成了亿万富翁
查看>>
HDOJ-4505 小Q系列故事——电梯里的爱情
查看>>
【转】Navigation Drawer(导航抽屉)
查看>>
Linux Shell常用技巧(十)
查看>>
【从零之三(更)】自定义类中调用讯飞语音包错误解决办法
查看>>
【源代码】LinkedHashMap源代码剖析
查看>>
Android InputStream转Bitmap
查看>>
记录水电系统开发的心理【1】
查看>>