公告/消息提示从右向左循环滚动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%);
  }
}
相关推荐
风骏时光牛马19 分钟前
数据可视化管理平台
前端
哎哟喂呢哈28 分钟前
VedioJS 10
javascript·html5
仿生狮子5 小时前
OpenAI 攻下千禧年难题之后,开发者似乎无动于衷
前端·数学·vibecoding
夏幻灵8 小时前
JavaScript this 面试:五种绑定规则、优先级与常见面试陷阱
开发语言·javascript·面试
Lvan的前端笔记8 小时前
docker:每个前端项目一个 Nginx 容器还是只有一个Nginx容器
前端·nginx·docker
三天不学习9 小时前
Egg.js 4 突然爆火,原因是否归结于AI 原生落地需求爆发?
前端·javascript·全栈·egg.js
xcs1940510 小时前
前端 vue 的前端页面debugger 进不去
前端·javascript·vue.js
明月_清风11 小时前
Deno 终局来了:从挑战 Node 到被 Cloudflare 收编
前端·后端·node.js
Csvn12 小时前
框架性能优化
前端
雪芽蓝域zzs13 小时前
第 5 节:Marker 点击弹出 InfoWindow 信息窗口
vue.js