公告/消息提示从右向左循环滚动vue

1.图示

2.代码

animationDuration(滚动时间),可以根据提示字数的多少进行修改

html 复制代码
<div class="base-header-notice">
      <img
          src="@/assets/images/notice.png"
          style="width:16px;height:16px;margin-right:5px;"
      >
      <div class="notice-scroll-wrap">
          <div
              class="base-header-notice-text"
              :style="{
                  animationDuration: '10s',
                  animationPlayState: 'running' 
              }"
          >
            <div style="color: #4377FF;">
               2026年测试时间:03月17日至04月17日!
            </div>
          </div>
      </div>
</div>
css 复制代码
.base-header-notice {
  display: flex;
  align-items: center;
  margin-right: 10px;
  width: 300px;
  overflow: hidden;

  .notice-scroll-wrap {
    width: 100%;
    overflow: hidden;
    position: relative;

    .base-header-notice-text {
      display: inline-block;
      white-space: nowrap;
      animation: scrollText linear infinite;
      will-change: transform;
      /* 让文字从最右侧外开始 */
      padding-left: 100%; 
    }
  }
}


/* 滚动动画:从右往左移动 */
@keyframes scrollText {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-100%);
  }
}
相关推荐
San813_LDD13 小时前
[C语言]《Dev-C++ 报错解决手册(Day0607 精华版)》
java·前端·javascript
xiaofeichaichai19 小时前
Webpack
前端·webpack·node.js
问心无愧051320 小时前
ctf show web入门111
android·前端·笔记
唐某人丶20 小时前
模型越来越强,我们还需要 Agent 工程吗?—— 从价值重估到 Harness 实践
前端·agent·ai编程
智码看视界20 小时前
现代Web开发基础:全栈工程师的起航点
前端·后端·c5全栈
JS菌20 小时前
手写一个 AI Agent 全栈项目:从沙箱执行到子智能体的完整实现
前端·人工智能·后端
excel21 小时前
HLS TS 文件损坏的元凶:Git 提交与拉取
前端
Aphasia3111 天前
https连接传输流程
前端·面试
徐小夕1 天前
万字长文!千万级文档 RAG 知识库系统落地实践
前端·算法·github