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>
相关推荐
晨枫阳20 小时前
不同语言的元组对比
java·前端·javascript
柒儿吖21 小时前
Electron for 鸿蒙PC 窗口问题完整解决方案
javascript·electron·harmonyos
flashlight_hi1 天前
LeetCode 分类刷题:404. 左叶子之和
javascript·算法·leetcode
木易 士心1 天前
th-table 中 基于双字段计算的表格列展示方案
前端·javascript·angular.js
toooooop81 天前
uniapp多个页面监听?全局监听uni.$emit/$on
前端·javascript·uni-app
爱泡脚的鸡腿1 天前
uni-app D4 实战(小兔鲜)
前端·vue.js·架构
星火飞码iFlyCode1 天前
iFlyCode+SpecKit应用:照片等比智能压缩功能实现
前端·javascript
广白1 天前
钉钉小程序直传文件到 阿里云OSS
前端·vue.js·uni-app
GISer_Jing1 天前
3DThreeJS渲染核心架构深度解析
javascript·3d·架构·webgl
摇滚侠1 天前
Vue 项目实战《尚医通》,完成订单详情静态的搭建,笔记47
vue.js·笔记