可视化大屏-实现自动滚动

一、背景:可视化大屏通常需要用到自动滚动的效果,本文主要采用的是vue-seamless-scroll 组件来实现(可参考官方文档

二、实现效果:

自动滚动

三、代码实现:

解题思路:

1.先安装依赖包

复制代码
npm install vue-seamless-scroll --save
或
yarn add vue-seamless-scroll
或
<script src="vue-seamless-scroll.min.js"></script>

2.完整源码实现如下:

复制代码
<template>
  <div class="mb-1" v-if="props.title">
    <span class="eq-blue-button">{{ props.title }}</span>
  </div>
  <vue3-seamless-scroll
  class="scroll"
  :class="heightClass"
  :list="list" 
  :hover="scrollOption.hover"
  :step="scrollOption.setp"
  :direction="scrollOption.direction"
  :limitScrollNum="scrollOption.limitScrollNum"
  >
  <!-- <slot name="slotScroll" :list="list"></slot> 注:如果想要封装成组件可以使用插槽方式 -->
  <!-- 下面代码为具体业务的页面显示代码-->
  <div class="eq-list" v-for="(item, index) in list" :key="index">
    <div class="eq-tr">{{ item.name }}</div>
    <div
      class="eq-tr2 flex" :class="[isShowUnit? 'justify-between': 'justify-center']"
      :style="{
        color: textColor,
        'font-Weight': props.fontWeight,
        'font-size': props.fontSize,
      }"
      >
      <span>{{ item.value }}</span>
      <span>{{ item.unit }}</span>
    </div>
  </div>
  </vue3-seamless-scroll>
</template>
<script lang="ts" setup>
import { ref,computed } from 'vue';
import { Vue3SeamlessScroll } from 'vue3-seamless-scroll';
const props = defineProps({
  list: {  //数据源  自动滚动 必传 
    type: Array,
    default: () => [],
  },
  scrollOptions: {  // 滚动的配置 比如 滚动方向、滚动达到什么数量开始滚动等
    type: Object,
    default: () => ({}),
  },
   heightClass: { // 滚动的高度 可以自己写 比如换成 .名称{height: '对应的高度'}
    type: String,
    default: "heightMidel"
  },
  title: {
    type: String,
    default: '',
  },
  textColor: {
    type: String,
    default: '#3cc094',
  },
  fontSize: {
    type: String,
    default: '',
  },
  fontWeight: {
    type: String,
    default: '500',
  },
  key: {
    type: String,
    default: '0',
  },
  isShowUnit: {
    type: Boolean,
    default: false,
  }
});
const scrollOption = ref({
  hover: true,  // 鼠标经过触发的事件 默认是true
  setp: 0.3, // 数值越大速度滚动越快
  limitScrollNum: 8,  // 开始无缝滚动的数据量 默认5
  hoverStop: true, // 是否开启鼠标悬停stop
  direction: 'up', // down向下 up向上 left 向左 right向右
  openWatch: true, // 开启数据实时监控刷新dom
  singleHeight: 10, //单步运动停止的高度(默认值0是无缝不停止的滚动)
  ...props.scrollOptions
})
</script>
<style lang="less" scoped>
.scroll {
  overflow: hidden;
}
.heightMidel {
  height: 36vh;
}
.heightLarge {
  height: 51vh;
}
.eq-box {
  color: #fff;
  margin: 0.6rem 0.3rem;
}
.eq-border-box {
  border: 1px solid #135daf;
  padding-right: 4px;
}
.eq-center {
  margin: 0px 5px;
  border: 1px solid #135daf;
}
.eq-blue-button {
  background: #2047b8;
  padding: 4px 16px;
  font-size: 0.8rem;
  font-weight: 500;
}
.eq-list {
  display: flex;
  border: 1px solid #1857f133;
  width: 100%;
}
.eq-tr {
  width: 60%;
  padding: 5px 8px;
  border-right: 1px solid #1857f133;
  font-size: 0.8rem;
  text-align: center;
}
.eq-tr2 {
  width: 40%;
  padding: 5px 8px;
  font-size: 0.8rem;
}
.text-green {
  color: #3de5ad;
}
.border-left {
  border-left: 1px solid #1857f133;
}

</style>
相关推荐
阿里巴巴P8资深技术专家16 小时前
2025 年度总结:在坚持与突破中前行
java·vue.js·人工智能·年终总结·2025
闲蛋小超人笑嘻嘻17 小时前
Vue 的异步更新机制和 $nextTick 的用法
前端·javascript·vue.js
GhostPaints17 小时前
Vue 2 项目中 template 使用可选链 ?. 导致的诡异编译报错及 webpack loader 配置坑
前端·vue.js·webpack
Code知行合壹17 小时前
Vue.js基础入门
javascript·vue.js·ecmascript
daols8817 小时前
vue 表格 vxe-table 手动操作单元格范围选择,手动选择 excel 指定区域的用法
vue.js·excel·vxe-table
小二·18 小时前
Vue Router 4 完全指南:动态路由、权限控制、懒加载与性能优化
前端·javascript·vue.js
不想秃头的程序员19 小时前
Vue3 defineModel 完全指南:从基础使用到进阶技巧
前端·vue.js·面试
不想秃头的程序员19 小时前
🔥Vue3 动态组件‘component’全解析
前端·vue.js·面试
天蓝色的鱼鱼19 小时前
让 JSON 数据可视化:两款 Vue 组件实战解析
前端·vue.js
泰勒疯狂展开19 小时前
Vue3研学-computed计算属性
前端·javascript·vue.js