vue:实现顶部消息横向滚动通知

前言

系统顶部展示一个横向滚动的消息通知,就是消息内容从右往左一直滚动。

效果如下:

代码

使用

javascript 复制代码
<template>
  <div class="notic-bar">
    <img :src="notic" class="notice-img" />
    <div class="notice-bar-container">
      <div class="notice-bar__wrap">
        <div
          v-for="(item, index) in list"
          :key="index"
          class="notice-bar__wrap_text"
        >
          {{ item }}
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import notic from "../../public/notic.png";
const list = [
  "开发不易,感谢理解",
  "",
  "感谢您的理解",
  "",
  "您的支持是我继续完善的动力",
];
</script>

<style lang="scss" scoped>
.notic-bar {
  display: flex;
  background: #67c23a;
  margin: 5px;
  border-radius: 5px;
  padding: 2px 5px;
}
.notice-bar-container {
  display: flex;
  width: calc(100% - 30px);
  height: 20px;
  overflow: hidden;
  margin-left: 5px;
}
.notice-img {
  width: 20px;
  height: 20px;
}
.notice-bar__wrap {
  margin-left: 10px;
  display: flex;
  animation: move 20s linear infinite;
  line-height: 20px;
  color: #f5f6f7;

  .notice-bar__wrap_text {
    width: max-content;
    min-width: 100px;
  }
}
@keyframes move {
  0% {
    transform: translateX(100%);
  }
  100% {
    transform: translateX(-100%);
  }
}
</style>
相关推荐
前端 贾公子1 天前
v-if 与 v-for 的优先级对比
开发语言·前端·javascript
小二·1 天前
Pinia 完全指南:用 TypeScript 构建可维护、可测试、可持久化的 Vue 3 状态管理
javascript·vue.js·typescript
bug总结1 天前
Vue3 实现后台管理系统跳转大屏自动登录功能
前端·javascript·vue.js
小二·1 天前
Vue 3 组件通信全方案详解:Props/Emit、provide/inject、事件总线替代与组合式函数封装
前端·javascript·vue.js
be or not to be1 天前
CSS 定位机制与图标字体
前端·css
Moment1 天前
如何在前端编辑器中实现像 Ctrl + Z 一样的撤销和重做
前端·javascript·面试
Rysxt_1 天前
Vue.js 中 LocalStorage 与 SessionStorage 深度实践指南
vue.js·localstorage·sessionstorage
小猪猪屁1 天前
权限封装不是写个指令那么简单:一次真实项目的反思
前端·javascript·vue.js
我的写法有点潮1 天前
如何取消Vue Watch监听
前端·javascript·vue.js
童心虫鸣1 天前
如何在Vue中传递函数作为Prop
前端·vue.js