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>
相关推荐
scan72421 小时前
pydantic格式输出
服务器·前端·javascript
ZC跨境爬虫21 小时前
跟着MDN学HTML_day44:(ProcessingInstruction接口)
前端·javascript·ui·html·媒体
i220818 Faiz Ul1 天前
高校教务|教务管理|基于springboot+vue的高校教务管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·高校教务系统
ZC跨境爬虫1 天前
跟着MDN学HTML_day_45:(EventTarget接口)
前端·javascript·ui·html·媒体
漂移的电子1 天前
【el-tree】外层多选,某个属性内层单选
前端·javascript·vue.js
DFT计算杂谈1 天前
AMSET 设置多核并行计算
java·前端·css·html·css3
前端老石人1 天前
CSS 值定义语法
前端·css
sheeta19981 天前
Vue 前端基础笔记
前端·vue.js·笔记
前端那点事1 天前
别再写垃圾组件!Vue3 如何设计「真正可复用」的高质量通用组件
前端·vue.js
卷帘依旧1 天前
JavaScript 中的 Symbol
前端·javascript