<el-table :data="tableData" stripe class="swiper-page-table" ref="table" height="100%" > <el-table-column type="index" label="序号" width="50"> </el-table-column> <el-table-column prop="date" label="时间" width="120"> </el-table-column> <el-table-column prop="name" label="姓名" width="140"> </el-table-column> <el-table-column prop="address" label="地址" min-width="220"> </el-table-column> </el-table> mounted() { this.tableScroll() }, methods: { tableScroll(){ const table = this.$refs.table; // 拿到表格中承载数据的div元素 const divData = table.bodyWrapper; // 拿到元素后,对元素进行定时增加距离顶部距离,实现滚动效果(此配置为每100毫秒移动1像素) setInterval(() => { // 元素自增距离顶部1像素 divData.scrollTop += 1; // 判断元素是否滚动到底部(可视高度+距离顶部=整个高度) if (divData.clientHeight + divData.scrollTop == divData.scrollHeight) { // 重置table距离顶部距离 divData.scrollTop = 0; } }, 30); // 滚动速度 } } <style lang="scss" scoped> .app-container { // 去除滚动的滚动条 ::v-deep .el-table--scrollable-y .el-table__body-wrapper{ overflow-y: hidden; } } </style>
亲测可用~
标签:vue,滚动,元素,距离,element,ui,divData,scrollTop,table From: https://www.cnblogs.com/bisiyuan/p/16847186.html