Vue Element-ui 之 el-table自动滚动
首先是 div结构布局
<div id="scrollId">//对el-table盒子设置 id 属性
<div style="height: 100%;">
<el-table row-class-name="tr_style" :stripe="true" :data="tableData"
:show-header="false"
:cell-style="{borderColor:'rgba(9, 14, 34, 1)'}"
:header-cell-style="{borderColor:'rgba(9, 14, 34, 0.5)',fontWeight:'400',background:'#0d1d3f',color:'#fff'}">
<el-table-column align="center" border v-for="(item,index) in cellData" :key="index" :prop="item.prop"></el-table-column>
</el-table>
</div>
</div>
data定义属性:
data() {
return {
scrollTimer: null, // 滚动定时器
pauseTimer: null, // 暂停定时器
scrollId: 'scrollId', // 滚动容器id
scrollDirection: 'down' // 滚动方向 up向上 down向下
};
},
在methods内添加以下方法
//滚动条触发事件
// 数据加载完成方法
dataCompleteFun() {
// 开启滚动
this.autoScroll()
},
autoScroll() {
if (document.getElementById("scrollId")) {
const scrollHeight = document.getElementById("scrollId").scrollHeight
const clientHeight = document.getElementById("scrollId").clientHeight
const scroll = scrollHeight - clientHeight
// 滚动长度为0
if (scroll === 0) {
return
}
}
// 触发滚动方法
this.scrollFun()
// 去除点击监听
window.document.removeEventListener('click', this.pauseScroll)
// 重设点击监听
window.document.addEventListener('click', this.pauseScroll, false) },
pauseScroll() {
// 定时器不为空
if (this.scrollTimer) {
// 清除定时器
clearInterval(this.scrollTimer)
this.scrollTimer = null
// 一秒钟后重新开始定时器
this.pauseTimer = setTimeout(() => {
this.scrollFun()
}, 2000)
}
},
scrollFun() {
// 如果定时器存在
if (this.scrollTimer) {
// 则先清除
clearInterval(this.scrollTimer)
this.scrollTimer = null
}
this.scrollTimer = setInterval(() => {
// 获取滚动条高度
if (document.getElementById("scrollId")) {
const scrollHeight = document.getElementById("scrollId").scrollHeight
const clientHeight = document.getElementById("scrollId").clientHeight
const scroll = scrollHeight - clientHeight
// 获取当前滚动条距离顶部高度
const scrollTop = document.getElementById("scrollId").scrollTop
// 向下滚动
if (this.scrollDirection === 'down') {
// 设置滚动速度 可更改 数字 2 为你想要的长度
const temp = scrollTop + 2
document.getElementById("scrollId").scrollTop = temp // 滚动
// 距离顶部高度 大于等于 滚动长度
if (scroll <= temp) {
// 滚动到底部 停止定时器
clearInterval(this.scrollTimer)
this.scrollTimer = null
// 改变方向
this.scrollDirection = 'up'
// 一秒后重开定时器
setTimeout(() => {
this.scrollFun()
}, 1000)
}
// 向上滚动
} else if (this.scrollDirection === 'up') {
const temp = scrollTop - 2
document.getElementById("scrollId").scrollTop = temp // 滚动
// 距离顶部高度 小于等于 0
if (temp <= 0) {
// 滚动到底部 停止定时器
clearInterval(this.scrollTimer)
this.scrollTimer = null
// 改变方向
this.scrollDirection = 'down'
// 一秒后重开定时器
setTimeout(() => {
this.scrollFun()
}, 1000)
}
}
}
}, 150)
},
在methods外,与methods同级,添加以下生命周期方法
destroyed() {
// 清理定时器
clearTimeout(this.pauseTimer)
this.pauseTimer = null
clearInterval(this.scrollTimer)
this.scrollTimer = null
// 清理点击监听
window.document.removeEventListener('click', this.pauseScroll)
},
updated() {
this.dataCompleteFun()
},
自此 el-table自动滚动结束
Vue Element-ui 之 el-table自动滚动的更多相关文章
- Vue+element ui table 导出到excel
需求: Vue+element UI table下的根据搜索条件导出当前所有数据 参考: https://blog.csdn.net/u010427666/article/details/792081 ...
- vue + element ui 实现实现动态渲染表格
前言:之前需要做一个页面,能够通过表名动态渲染出不同的表格,这里记录一下.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9786326.html 网站地址:我的 ...
- vue + element ui 表格自定义表头,提供线上demo
前言:工作中用到 vue+element ui 的前端框架,需要使用自定义表头,需要使用 re.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9710826.h ...
- vue+element ui 的表格列使用组件
前言:工作中用到 vue+element ui 的前端框架,有这个场景:很多表格的列有许多一样的,所以考虑将列封装为组件.转载请注明出处:https://www.cnblogs.com/yuxiaol ...
- vue+element ui 的tab 动态增减,切换时提示用户是否切换
前言:工作中用到 vue+element ui 的前端框架,动态添加 Tab,删除 Tab,切换 Tab 时提示用户是否切换等,发现 element ui 有一个 bug,这里记录一下如何实现.转载 ...
- vue + element ui 阻止表单输入框回车刷新页面
问题 在 vue+element ui 中只有一个输入框(el-input)的情况下,回车会提交表单. 解决方案 在 el-form 上加上 @submit.native.prevent 这个则会阻止 ...
- vue+element ui 的时间控件选择 年月日时分
前言:工作中用到 vue+element ui 的前端框架,需要选择年月日时分,但element ui官网demo有没有,所以记录一下.转载请注明出处:https://www.cnblogs.com/ ...
- Vue+Element UI 实现视频上传
一.前言 项目中需要提供一个视频介绍,使用户能够快速.方便的了解如何使用产品以及注意事项. 前台使用Vue+Element UI中的el-upload组件实现视频上传及进度条展示,后台提供视频上传AP ...
- 分享一个自搭的框架,使用Spring boot+Vue+Element UI
废弃,新的:https://www.cnblogs.com/hackyo/p/10453243.html 特点:前后端分离,可遵循restful 框架:后端使用Spring boot,整合了aop.a ...
- Vue + Element UI 实现权限管理系统
Vue + Element UI 实现权限管理系统 前端篇(一):搭建开发环境 https://www.cnblogs.com/xifengxiaoma/p/9533018.html
随机推荐
- IDEA中使用JDBC连接MySQL数据库报错:No appropriate protocol (protocol is disabled or cipher suites are inappropriate) 的解决方法
在IDEA中使用JDBC连接MySQL,程序运行之后报错: 定位到第16行: 根据上面报错提示,在url参数字段最前面添加参数 useSSL=false : 再次运行程序,成功连接到数据库!
- springboot条件注册Condition注解
环境识别 import org.springframework.context.annotation.Condition; import org.springframework.context.ann ...
- 记录一次线上gitlab11.x升级gitlab14.x版本操作
前言:gitlab11升级到14还是有挺多需要注意的坑,也算是做一次积累吧,升级前后,gitalb的WEB界面也变化了很多,升级过程需要注意的地方我放到最后说明,挺关键的 一.首先需要下载好要升级的包 ...
- Git 仓库7K stars!学Java开源项目austin要多久?
我是3y,一年CRUD经验用十年的markdown程序员常年被誉为职业八股文选手 开源项目消息推送平台austin仓库地址: 消息推送平台推送下发[邮件][短信][微信服务号][微信小程序][企业微 ...
- Javaweb学习第十二弹--Request和Response
XML配置方式编写Servlet 3.0版本之前,仅仅支持XML配置文件的配置方式 1.编写Servlet类 2.在web.xml中配置该Servlet Request和Response Reques ...
- BL808:【M1s DOCK开发板】与LVGL 使用体验
前言 念春时已夏,恋冬雪已融. 总是感叹时光匆匆,便努力在在平凡中挣扎,在平庸中努力,在平淡中积累.奈何时代飞速发展,时间又被工作占用,外加生活中的诱惑又太多了,很多想学.想做.想超越的事,都被抛之一 ...
- 基于Sekiro的jsRPC的使用和安装
什么是jsRPC 说实话在介绍 JSRPC 我向大家推荐一个库 Selenium-wire 感觉和JSrpc的原理很像 RPC指远程过程调用,APP里面的RPC大家比较熟悉了. 那什么是jsRPC,顾 ...
- 53.cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
1.cin 用法1:最基本,也是最常用的用法,输入一个数字: #pragma warning(disable:4996) #define _CRT_SECURE_NO_WARNINGS 1 #incl ...
- Mathematica制作和使用程序包
步骤 这里拿你制作并且使用一个程序包lost为例子 新建一个空白.wl文档,输入代码如下 BeginPackage[ "MyPkg`"] MainFunction::usage = ...
- vmware workstation 版本合集
各版本序列号 10.x:1Z0G9-67285-FZG78-ZL3Q2-234JG 11.x:YG74R-86G1M-M8DLP-XEQNT-XAHW2 12.x:ZC3TK-63GE6-481JY- ...