vue自定義table表如何實(shí)現(xiàn)內(nèi)容上下循環(huán)滾動(dòng)
需求
對(duì)一段table表數(shù)據(jù)進(jìn)行異常與正常類型的分類處理;
異常數(shù)據(jù)固定于table表內(nèi)上方顯示;
正常數(shù)據(jù)則在異常數(shù)據(jù)下方實(shí)現(xiàn)循環(huán)滾動(dòng)效果;
(若正常數(shù)據(jù)高度未溢出table表高度,正常顯示即可,無(wú)需滾動(dòng))
效果圖展示
代碼核心部分
<!-- html 部分--> <!-- scrollWrap: 滾動(dòng)區(qū)域; scrollWrapHeight:table總高度 - header高度 - 異常數(shù)據(jù)高度 --> <div class="scrollWrap" :style="{ height: scrollWrapHeight + 'px', overflowY: 'hidden', }" > <!-- scrollNum:滾動(dòng)時(shí),復(fù)制正常table數(shù)據(jù)一份,用于上下循環(huán)滾動(dòng)無(wú)縫銜接 --> <div :class="scrollNum > 1 ? 'scroll' : ''" :style="{ animationDuration: time + 's', }" v-for="(a, index) in scrollNum" :key="index" > <div class="table-bodySuccess" v-for="(item, index) in successData" :key="index" :style="{ background: successBgColor(index), }" > <div class="table-body-item-title"> {{ item.name }} </div> <div class="table-body-item-title"> <div class="circle"></div> </div> <div class="table-body-item-title">{{ item.tampNum }}℃</div> <div class="table-body-item-title">{{ item.eleNum }}A</div> </div> </div> </div> <!-- css 部分--> .scrollWrap::-webkit-scrollbar { width: 0 !important; } .scroll { animation: scrollData 10s infinite linear; } @keyframes scrollData { from { transform: translateY(0px); } to { transform: translateY(-100%); } }
完整代碼展示
<template> <div class="left"> <div class="table"> <div class="table-header"> <div class="table-header-item-title">名稱</div> <div class="table-header-item-title">狀態(tài)</div> <div class="table-header-item-title">數(shù)據(jù)標(biāo)題1</div> <div class="table-header-item-title">數(shù)據(jù)標(biāo)題2</div> </div> <div class="table-bodyError" v-for="(item, index) in errData" :key="index" :style="{ background: errBgColor(index) }" > <div class="table-body-item-title"> {{ item.name }} </div> <div class="table-body-item-title"> <div class="circle"></div> </div> <div class="table-body-item-title"> {{ item.tampNum }} </div> <div class="table-body-item-title"> {{ item.eleNum }} </div> </div> <div class="scrollWrap" :style="{ height: scrollWrapHeight + 'px', overflowY: 'hidden', }" > <div :class="scrollNum > 1 ? 'scroll' : ''" :style="{ animationDuration: time + 's', }" v-for="(a, index) in scrollNum" :key="index" > <div class="table-bodySuccess" v-for="(item, index) in successData" :key="index" :style="{ background: successBgColor(index), }" > <div class="table-body-item-title"> {{ item.name }} </div> <div class="table-body-item-title"> <div class="circle"></div> </div> <div class="table-body-item-title">{{ item.tampNum }}℃</div> <div class="table-body-item-title">{{ item.eleNum }}A</div> </div> </div> </div> </div> </div> </template>
<script> export default { name: 'test', data() { return { // 調(diào)節(jié)滾動(dòng)速率 time: 15, errData: [ { name: 11, status: 0, tampNum: 10, eleNum: 15 }, { name: 22, status: 0, tampNum: 10, eleNum: 15 }, { name: 33, status: 0, tampNum: 10, eleNum: 15 }, ], successData: [ { name: 'aaa', status: 1, tampNum: 10, eleNum: 15 }, { name: 'bbb', status: 1, tampNum: 10, eleNum: 15 }, { name: 'ccc', status: 1, tampNum: 10, eleNum: 15 }, { name: 'ddd', status: 1, tampNum: 10, eleNum: 15 }, { name: 'eee', status: 1, tampNum: 10, eleNum: 15 }, { name: 'fff', status: 1, tampNum: 10, eleNum: 15 }, { name: 'ggg', status: 1, tampNum: 10, eleNum: 15 }, { name: 'hhh', status: 1, tampNum: 10, eleNum: 15 }, { name: 'iii', status: 1, tampNum: 10, eleNum: 15 }, { name: 'jjj', status: 1, tampNum: 10, eleNum: 15 }, { name: 'kkk', status: 1, tampNum: 10, eleNum: 15 }, ], } }, computed: { errBgColor: function () { return function (index) { if (index % 2 === 0) { return '#e8f7ff' } else { return '#ffffff' } } }, successBgColor: function () { return function (index) { if (this.errData.length % 2 === 0) { if (index % 2 === 0) { return '#e8f7ff' } else { return '#ffffff' } } else { if (index % 2 === 0) { return '#ffffff' } else { return '#e8f7ff' } } } }, // 滾動(dòng)層高度 scrollWrapHeight: function () { // left高度 - table-header高度 - table-bodyError高度 * 個(gè)數(shù) return 600 - 52 - this.errData.length * 52 }, // 滾動(dòng)層份數(shù),當(dāng)內(nèi)容溢出scrollWrapHeight,復(fù)制兩份,添加滾動(dòng)動(dòng)畫(huà) // 否則就一份,不填加滾動(dòng)動(dòng)畫(huà) scrollNum: function () { let successHeight = this.successData.length * 52 if (successHeight > this.scrollWrapHeight) { return 2 } else { return 1 } }, }, } </script>
<style lang="less" scoped> .left { width: 520px; height: 600px; background-color: #fab4b4; border-bottom: 1px solid red; position: relative; .table-header { width: 100%; background-color: skyblue; color: #e1f3ff; font-size: 16px; font-weight: 700; display: flex; .table-header-item-title { height: 52px; width: 100%; display: flex; justify-content: center; align-items: center; } } .table-bodyError, .table-bodySuccess { width: 100%; color: red; font-size: 16px; display: flex; .table-body-item-title { width: 100%; height: 52px; display: flex; justify-content: center; align-items: center; .circle { width: 12px; height: 12px; background: #ea4141; border-radius: 50%; } } } .table-bodySuccess { color: #000; .table-body-item-title { .circle { background: #29b153; } } } .scrollWrap::-webkit-scrollbar { width: 0 !important; } .scroll { animation: scrollData 10s infinite linear; } @keyframes scrollData { from { transform: translateY(0px); } to { transform: translateY(-100%); } } } </style>
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- vue封裝實(shí)現(xiàn)自動(dòng)循環(huán)滾動(dòng)的列表
- vue實(shí)現(xiàn)循環(huán)滾動(dòng)圖片
- vue實(shí)現(xiàn)列表無(wú)縫循環(huán)滾動(dòng)
- vue實(shí)現(xiàn)公告消息橫向無(wú)縫循環(huán)滾動(dòng)
- 基于vue實(shí)現(xiàn)循環(huán)滾動(dòng)列表功能
- Vue實(shí)現(xiàn)一種簡(jiǎn)單的無(wú)限循環(huán)滾動(dòng)動(dòng)畫(huà)的示例
- vue實(shí)現(xiàn)循環(huán)滾動(dòng)列表
相關(guān)文章
vue使用mint-ui實(shí)現(xiàn)下拉刷新和無(wú)限滾動(dòng)的示例代碼
本篇文章主要介紹了vue使用mint-ui實(shí)現(xiàn)下拉刷新和無(wú)限滾動(dòng)的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11vue-cli3.0+element-ui上傳組件el-upload的使用
這篇文章主要介紹了vue-cli3.0+element-ui上傳組件el-upload的使用,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-12-12Vue實(shí)現(xiàn)拖拽穿梭框功能四種方式實(shí)例詳解
這篇文章主要介紹了Vue實(shí)現(xiàn)拖拽穿梭框功能四種方式,使用原生js實(shí)現(xiàn)拖拽,VUe使用js實(shí)現(xiàn)拖拽穿梭框,結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-09-09vue實(shí)現(xiàn)自定義H5視頻播放器的方法步驟
這篇文章主要介紹了vue實(shí)現(xiàn)自定義H5視頻播放器的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07vue中element 的upload組件發(fā)送請(qǐng)求給后端操作
這篇文章主要介紹了vue中element 的upload組件發(fā)送請(qǐng)求給后端操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09Vue3+Vite如何解決“找不到模塊“@/components/xxx.vue”或其相應(yīng)的類型聲明ts(2307)”
在Vue項(xiàng)目中使用Vite時(shí),可能因版本差異而需修改tsconfig.app.json而非tsconfig.json以解決編譯錯(cuò)誤,本文分享個(gè)人解決經(jīng)驗(yàn),供參考2024-10-10