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自定義指令的創(chuàng)建和使用方法實(shí)例分析
這篇文章主要介紹了vue自定義指令的創(chuàng)建和使用方法,結(jié)合完整實(shí)例形式分析了vue.js創(chuàng)建及使用自定義指令的相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2018-12-12
淺談vue中document.getElementById()拿到的是原值的問(wèn)題
這篇文章主要介紹了淺談vue中document.getElementById()拿到的是原值的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-07-07
vue3+ts封裝axios實(shí)例以及解決跨域問(wèn)題
在前端開(kāi)發(fā)中,使用axios進(jìn)行數(shù)據(jù)請(qǐng)求是常見(jiàn)的做法,封裝axios可以統(tǒng)一請(qǐng)求頭處理、方便接口管理、配置多攔截器等,提高代碼的可維護(hù)性和重用性,本文詳細(xì)記錄了axios的封裝過(guò)程,包括安裝、配置跨域處理、接口管理文件的創(chuàng)建等2024-09-09
UNIapp實(shí)現(xiàn)局域網(wǎng)內(nèi)在線升級(jí)的操作方法
這篇文章主要介紹了UNIapp實(shí)現(xiàn)局域網(wǎng)內(nèi)在線升級(jí)的操作方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2024-03-03
使用VueRouter的addRoutes方法實(shí)現(xiàn)動(dòng)態(tài)添加用戶的權(quán)限路由
這篇文章主要介紹了使用VueRouter的addRoutes方法實(shí)現(xiàn)動(dòng)態(tài)添加用戶的權(quán)限路由,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-06-06
vue獲取v-for異步數(shù)據(jù)dom的解決問(wèn)題
這篇文章主要介紹了vue獲取v-for異步數(shù)據(jù)dom的解決問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03
完美解決vue 項(xiàng)目開(kāi)發(fā)越久 node_modules包越大的問(wèn)題
這篇文章主要介紹了vue 項(xiàng)目開(kāi)發(fā)越久 node_modules包越大的問(wèn)題及解決方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-09-09
基于Vue實(shí)現(xiàn)文件上傳的幾種實(shí)現(xiàn)方式
文件上傳是web開(kāi)發(fā)中一個(gè)常見(jiàn)的需求,Vue.js作為一款流行的前端框架,也提供了方便的方法來(lái)實(shí)現(xiàn)文件上傳功能,下面這篇文章主要給大家介紹了關(guān)于基于Vue實(shí)現(xiàn)文件上傳的幾種實(shí)現(xiàn)方式,需要的朋友可以參考下2024-03-03
vue如何設(shè)置描點(diǎn)跳轉(zhuǎn)到對(duì)應(yīng)頁(yè)面
這篇文章主要介紹了vue如何設(shè)置描點(diǎn)跳轉(zhuǎn)到對(duì)應(yīng)頁(yè)面問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-05-05

