公告/消息提示从右向左循环滚动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%);
  }
}
相关推荐
kyriewen8 小时前
Anthropic 估值逼近万亿美元,Claude Sonnet 5 + Claude Science 一天两连发
前端·ai编程·claude
小徐_23339 小时前
Wot UI 2.2.0 发布:Button 新增 subtle,VideoPreview 预览体验继续增强
前端·微信小程序·uni-app
山河木马11 小时前
矩阵专题3-怎么创建投影矩阵(uProjectionMatrix)
javascript·webgl·计算机图形学
天蓝色的鱼鱼12 小时前
关于 CSS 你可能不知道的属性,但关键时刻很有用
前端·css
泯泷13 小时前
第 2 篇:设计第一套字节码:Opcode、Instruction 与 Constant Pool
前端·javascript·安全
妙码生花13 小时前
从 PHP 到 AI + Golang,程序员自救转型手记(十五):优化细节、网络请求封装
前端·后端·ai编程
泯泷13 小时前
第 1 篇:从 1 + 2 开始:亲手写出第一台 JSVM
前端·javascript·安全
团团崽_七分甜13 小时前
Spring Boot 核心知识点总结
前端
lichenyang45313 小时前
从一个按钮开始,理解 ASCF 框架到底在做什么
前端