纯css实现文字左右循环滚动播放效果

思路:由两个span模块组成,第一个为空的span内容,为的是实现第二个span内容缓慢出现的效果。

代码如下:

html 复制代码
   <div class="scrollingStyle">
       <span class="first-marquee"></span>
       <span class="second-marquee">系统通知:【{{scrollingText}} 发布于:{{time}}】</span>
   </div>
css 复制代码
  .scrollingStyle {
    font-size: 16px;
    width: 300px;
    overflow: hidden; /*超出文本的范围就隐藏*/
    white-space: nowrap; /*超出文本的范围不换行*/
    text-overflow: ellipsis; /*在文本的范围内,末尾以"..."的形式展示*/
  }
  .first-marquee {
  /*第一个span的播放速度*/
    -webkit-animation: 5s first-marquee 1s linear infinite normal;
    animation: 5s first-marquee linear 1s infinite normal;
    padding-right: 100%;
  }

  @keyframes first-marquee {
    0% {
      -webkit-transform: translate3d(0, 0, 0);
      transform: translate3d(0, 0, 0);
    }
    /* 向左移动 */
    100% {
      -webkit-transform: translate3d(-200%, 0, 0);
      transform: translate3d(-200%, 0, 0);
      display: none;
    }
  }

  .second-marquee {
    /* 第二个span的播完速度 */
    -webkit-animation: 25s first-marquee linear infinite normal;
    animation: 25s first-marquee linear infinite normal;
    padding-right: 53%;
  }

  @keyframes second-marquee {
    0% {
      -webkit-transform: translate3d(0%, 0, 0);
      transform: translate3d(0%, 0, 0);
    }
    100% {
      -webkit-transform: translate3d(-200%, 0, 0);
      transform: translate3d(-200%, 0, 0);
      display: none;
    }
  }
相关推荐
hoiii1877 分钟前
MATLAB SGM(半全局匹配)算法实现
前端·算法·matlab
会编程的土豆1 小时前
新手前端小细节
前端·css·html·项目
广州华水科技2 小时前
单北斗GNSS在桥梁形变监测中的应用与技术进展分析
前端
我讲个笑话你可别哭啊2 小时前
鸿蒙ArkTS快速入门
前端·ts·arkts·鸿蒙·方舟开发框架
CherryLee_12102 小时前
基于poplar-annotation前端插件封装文本标注组件及使用
前端·文本标注
特立独行的猫a2 小时前
C++轻量级Web框架介绍与对比:Crow与httplib
开发语言·前端·c++·crow·httplib
周航宇JoeZhou2 小时前
JB2-7-HTML
java·前端·容器·html·h5·标签·表单
代码小库2 小时前
【课程作业必备】Web开发技术HTML静态网站模板 - 校园动漫社团主题完整源码
前端·html
珹洺2 小时前
Bootstrap-HTML(二)深入探索容器,网格系统和排版
前端·css·bootstrap·html·dubbo
BillKu2 小时前
VS Code HTML CSS Support 插件详解
前端·css·html