vue如何實(shí)現(xiàn)列表自動(dòng)滾動(dòng)、向上滾動(dòng)的效果(vue-seamless-scroll)
vue實(shí)現(xiàn)列表自動(dòng)滾動(dòng)、向上滾動(dòng)的效果
研究了一個(gè)插件 列表自動(dòng)滾動(dòng)的插件vue-seamless-scroll
感受這是個(gè)做大屏可視化時(shí)可靠幫手
請欣賞一下效果圖
如圖所示可以看到 它自動(dòng)向上滾動(dòng) 以及鼠標(biāo)移動(dòng)進(jìn)入表格則停止?jié)L動(dòng)
這個(gè)使用起來也是非常的方便的,接下來我為各位老鐵記錄一下使用的過程
1.第一步進(jìn)行安裝
npm install vue-seamless-scroll --save
2.在main.js直接導(dǎo)入使用
import scroll from 'vue-seamless-scroll' Vue.use(scroll)
3.建立了一個(gè)Test.vue來使用(結(jié)合element-ui中的表格來一起實(shí)現(xiàn)的)
<template> <div id="app"> <div class="backround"> <div class="toptitle"> <div class="item">日期</div> <div class="item">姓名</div> <div class="item">地址</div> </div> <vue-seamless-scroll :data="listData" :class-option="optionHover" class="seamless-warp"> <el-table :data="listData" border :show-header="status" > <el-table-column prop="date" label="日期" > </el-table-column> <el-table-column prop="title" label="姓名" > </el-table-column> <el-table-column prop="test" label="地址" > </el-table-column> </el-table> </vue-seamless-scroll> </div> </div> </template> <script> export default { data () { return { status:false, listData: [ { 'title': '無縫滾動(dòng)第一行無縫滾動(dòng)第一行', 'date': '2017-12-16', 'test':'測試', 'test2':'測試2', 'test3':'測試3' }, { 'title': '無縫滾動(dòng)第二行無縫滾動(dòng)第二行', 'date': '2017-12-16', 'test':'測試', 'test2':'測試2', 'test3':'測試3' }, { 'title': '無縫滾動(dòng)第三行無縫滾動(dòng)第三行', 'date': '2017-12-16', 'test':'測試', 'test2':'測試2', 'test3':'測試3' }, { 'title': '無縫滾動(dòng)第四行無縫滾動(dòng)第四行', 'date': '2017-12-16', 'test':'測試', 'test2':'測試2', 'test3':'測試3' }, { 'title': '無縫滾動(dòng)第五行無縫滾動(dòng)第五行', 'date': '2017-12-16', 'test':'測試', 'test2':'測試2', 'test3':'測試3' }, { 'title': '無縫滾動(dòng)第六行無縫滾動(dòng)第六行', 'date': '2017-12-16', 'test':'測試', 'test2':'測試2', 'test3':'測試3' }, { 'title': '無縫滾動(dòng)第七行無縫滾動(dòng)第七行', 'date': '2017-12-16', 'test':'測試', 'test2':'測試2', 'test3':'測試3' }, ] } }, computed: { optionHover() { return { step: 0.5, // 數(shù)值越大速度滾動(dòng)越快 limitMoveNum: 2, // 開始無縫滾動(dòng)的數(shù)據(jù)量 this.dataList.length hoverStop: true, // 是否開啟鼠標(biāo)懸停stop direction: 1, // 0向下 1向上 2向左 3向右 openWatch: true, // 開啟數(shù)據(jù)實(shí)時(shí)監(jiān)控刷新dom singleHeight: 0, // 單步運(yùn)動(dòng)停止的高度(默認(rèn)值0是無縫不停止的滾動(dòng)) direction => 0/1 singleWidth: 0, // 單步運(yùn)動(dòng)停止的寬度(默認(rèn)值0是無縫不停止的滾動(dòng)) direction => 2/3 waitTime: 1000, // 單步運(yùn)動(dòng)停止的時(shí)間(默認(rèn)值1000ms) }; }, } } </script>
4.若是不嫌棄小弟的樣式丑可以在這里復(fù)制(各位大佬們也可以自己手寫自己帥氣的樣式喲,背景圖自己網(wǎng)上找一張即可)
<style lang="less" scoped> .backround{ width: 100%; height: 1000px; background-image: url("../assets/pageBg.png"); } /deep/ .el-table, /deep/ .el-table__expanded-cell{ background-color: transparent; } /* 表格內(nèi)背景顏色 */ /deep/ .el-table th, /deep/ .el-table tr, /deep/ .el-table td { background-color: transparent; color:white } .seamless-warp{ height: 200px; overflow: hidden; } /deep/.el-table .cell{ text-align: center; } /deep/.toptitle{ width: 100%; display: flex; background-color: gainsboro; margin-bottom: 10px; border:2px solid gainsboro; background-color: transparent; color:white } .item{ width: 33.3%; border-right:2px solid gainsboro; text-align: center; } </style>
重點(diǎn):若是有不明白的小伙伴,以及想深入學(xué)習(xí)的小伙伴們 可以點(diǎn)擊深入學(xué)習(xí) 進(jìn)入到對應(yīng)的插件演示文檔進(jìn)行學(xué)習(xí)呀
vue-seamless-scroll(一個(gè)簡單的基于vue.js的無縫滾動(dòng))
一般在數(shù)據(jù)可視化項(xiàng)目中經(jīng)常會看到無縫滾動(dòng)的表格,即輪播表,我們可以使用 vue-seamless-scroll 來實(shí)現(xiàn),使用起來也很方便
vue-seamless-scroll官網(wǎng):vue-seamless-scroll
1. 安裝
NPM
npm install vue-seamless-scroll --save
Yarn
yarn add vue-seamless-scroll
PNPM
pnpm add vue-seamless-scroll
2. 引入組件注冊
import VueSeamlessScroll from "vue-seamless-scroll"; export default { ? components: { VueSeamlessScroll } }
3. 使用
在實(shí)際項(xiàng)目中可能不止一個(gè)地方使用輪播表,所以我這里還是將其封裝為單獨(dú)一個(gè)組件可以復(fù)用,該組件默認(rèn)都是寬高100% * 100%,給定一個(gè)容器引入即可。樣式也是可以隨意調(diào)整的,傳入數(shù)據(jù)和配置項(xiàng)即可。具體配置項(xiàng)(class-option)看https://chenxuan0000.github.io/vue-seamless-scroll/zh/guide/properties.html#data
組件封裝
src/components/VueSeamlessScroll/index.vue
<template> ? <div class="vue-seamless-scroll"> ? ? <VueSeamlessScroll :data="listData" class="warp" :class-option="classOption"> ? ? ? <div class="row" v-for="item in listData" :key="item.id"> ? ? ? ? <div>{{ item.title }}</div> ? ? ? ? <div>{{ item.date }}</div> ? ? ? </div> ? ? </VueSeamlessScroll> ? </div> </template> <script> import VueSeamlessScroll from "vue-seamless-scroll"; export default { ? components: { VueSeamlessScroll }, ? props: { ? ? listData: { ? ? ? type: Array, ? ? ? default: () => [] ? ? }, ? ? classOption: { ? ? ? type: Object, ? ? ? default: () => {} ? ? } ? } }; </script> <style scoped> .vue-seamless-scroll { ? width: 100%; ? height: 100%; ? padding: 12px 5px; ? box-sizing: border-box; } .warp { ? width: 100%; ? height: 100%; ? overflow: hidden; } .row { ? width: 100%; ? display: flex; ? justify-content: space-between; ? margin-bottom: 5px; } </style>
組件引入使用
<template> ? <div class="index"> ? ? <div class="scroll-table"> ? ? ? <!-- 輪播組件 --> ? ? ? <VueSeamlessScroll :listData="listData" :classOption="{ step: 1, limitMoveNum: 5 }" /> ? ? </div>? ? </div> </template> <script> import VueSeamlessScroll from '@/components/VueSeamlessScroll' export default { ? data() { ? ? return { ? ? ? listData: [] ? ? } ? }, ? components: { VueSeamlessScroll }, ? mounted(){ ? ? this.getData() ? }, ? methods:{ ? ? // 獲取輪播數(shù)據(jù) ? ? getData() { ? ? ? setTimeout(() => { ? ? ? ? this.listData = [ ? ? ? ? ? { ? ? ? ? ? ? id: 1, ? ? ? ? ? ? title: "無縫滾動(dòng)第一行無縫滾動(dòng)第一行", ? ? ? ? ? ? date: "2017-12-16", ? ? ? ? ? }, ? ? ? ? ? { ? ? ? ? ? ? id: 2, ? ? ? ? ? ? title: "無縫滾動(dòng)第二行無縫滾動(dòng)第二行", ? ? ? ? ? ? date: "2017-12-16", ? ? ? ? ? }, ? ? ? ? ? { ? ? ? ? ? ? id: 3, ? ? ? ? ? ? title: "無縫滾動(dòng)第三行無縫滾動(dòng)第三行", ? ? ? ? ? ? date: "2017-12-16", ? ? ? ? ? }, ? ? ? ? ? { ? ? ? ? ? ? id: 4, ? ? ? ? ? ? title: "無縫滾動(dòng)第四行無縫滾動(dòng)第四行", ? ? ? ? ? ? date: "2017-12-16", ? ? ? ? ? }, ? ? ? ? ? { ? ? ? ? ? ? id: 5, ? ? ? ? ? ? title: "無縫滾動(dòng)第五行無縫滾動(dòng)第五行", ? ? ? ? ? ? date: "2017-12-16", ? ? ? ? ? }, ? ? ? ? ? { ? ? ? ? ? ? id: 6, ? ? ? ? ? ? title: "無縫滾動(dòng)第六行無縫滾動(dòng)第六行", ? ? ? ? ? ? date: "2017-12-16", ? ? ? ? ? }, ? ? ? ? ? { ? ? ? ? ? ? id: 7, ? ? ? ? ? ? title: "無縫滾動(dòng)第七行無縫滾動(dòng)第七行", ? ? ? ? ? ? date: "2017-12-16", ? ? ? ? ? }, ? ? ? ? ? { ? ? ? ? ? ? id: 8, ? ? ? ? ? ? title: "無縫滾動(dòng)第八行無縫滾動(dòng)第八行", ? ? ? ? ? ? date: "2017-12-16", ? ? ? ? ? }, ? ? ? ? ? { ? ? ? ? ? ? id: 9, ? ? ? ? ? ? title: "無縫滾動(dòng)第九行無縫滾動(dòng)第九行", ? ? ? ? ? ? date: "2017-12-16", ? ? ? ? ? }, ? ? ? ? ? { ? ? ? ? ? ? id: 10, ? ? ? ? ? ? title: "無縫滾動(dòng)第十行無縫滾動(dòng)第十行", ? ? ? ? ? ? date: "2017-12-16", ? ? ? ? ? }, ? ? ? ? ]; ? ? ? }, 200); ? ? }, ? }, } </script> <style scoped> .index { ? width: 100%; ? height: 100%; ? padding: 20px 0 0 20px; ? box-sizing: border-box; } .scroll-table { ? width: 350px; ? height: 300px; ? border: 1px dashed red; } </style>
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
webpack+vuex+axios 跨域請求數(shù)據(jù)的示例代碼
本篇文章主要介紹了webpack+vuex+axios 跨域請求數(shù)據(jù),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-03-03vue.js內(nèi)置組件之keep-alive組件使用
keep-alive是Vue.js的一個(gè)內(nèi)置組件。這篇文章主要介紹了vue.js內(nèi)置組件之keep-alive組件使用,需要的朋友可以參考下2018-07-07fullcalendar日程管理插件月份切換回調(diào)處理方案
這篇文章主要為大家介紹了fullcalendar日程管理插件月份切換回調(diào)處理的方案示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-03-03vue模塊移動(dòng)組件的實(shí)現(xiàn)示例
這篇文章主要介紹了vue模塊移動(dòng)組件的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05element-ui el-select下拉框el-date-picker彈出框定位問題解決方案(推薦)
項(xiàng)目開發(fā)過程中發(fā)現(xiàn)el-select和el-date-picker彈出框顯示時(shí)候,滾動(dòng)屏幕,導(dǎo)致彈出框定位出現(xiàn)問題,這篇文章主要介紹了element-ui el-select下拉框el-date-picker彈出框定位問題解決方案(推薦),需要的朋友可以參考下2024-07-07解決vue項(xiàng)目Error:Cannot find module‘xxx’類報(bào)錯(cuò)問題
當(dāng)npm運(yùn)行報(bào)錯(cuò)Error:Cannot find module 'xxx'時(shí),通常是因?yàn)閚ode_modules文件或依賴未正確安裝,解決步驟包括刪除node_modules和package-lock.json文件,重新運(yùn)行npm install,并根據(jù)需要安裝額外插件,若網(wǎng)絡(luò)問題導(dǎo)致安裝失敗2024-10-10