上拉加载更多....
利用better-scroll插件做移动端table可上下左右滑动且固定表头和列
发布日期:2022-02-19 23:50:23
浏览次数:35
分类:技术文章
本文共 3825 字,大约阅读时间需要 12 分钟。
上下左右滑动时固定表头、列&上拉加载
思路
显示结构
.cross | .row | .row |
---|---|---|
data.clos | data | data |
data.clos | data | data |
思路步骤
- 配置
BScroll
配置项 - 声明
BScroll
的scroll
事件函数:onScroll
,在里面取得所有.cross
/.row
/.clos
元素,并对每个元素添加transform
样式,且记录实时滚动的x,y
值。.cross
的x,y
实时同步;.row
的x
为0,y
同步;.clos
的x
同步,y
为0。 - 声明
BScroll
的pullUpLoad
事件(上拉加载)函数:onPullUpLoad
,在函数里获取数据,用this.$nextTick()
获取所有.cross
/.row
/.clos
元素,并对每个元素添加transform
样式,设置为声明时所记录的实时滚动的x,y
值。
代码
// html
// jsdata(){ return { scroller: null, X: 0, Y: 0, flag: false, }},_init(){ // 初始化配置 const that = this this.scroller = new BScroll(this.$refs.BScroll, { preventDefault: false, // 阻止浏览器默认行为 probeType: 3, // 1:非实时派发scroll事件; 2:在屏幕滑动的过程中实时的派发 scroll 事件; 3:不仅在屏幕滑动的过程中,而且在 momentum 滚动动画运行过程中实时派发 scroll 事件。 scrollX: true, // 启动x轴滚动 scrollY: true, // 启动y轴滚动 momentum: false, // 是否开启快速滑动 directionLockThreshold: 0, // 斜滑时,锁定一个方向滚动 bounce: { // 滑动到边缘时出现回弹动画 top: false, bottom: true, left: false, right: false }, pullUpLoad: { // 开启上拉加载,Boolean | Object threshold: 50 } }) function _onScroll() { // 滚动函数 const frozenCrosses = document.querySelectorAll('#wrapper .cross'); const frozenRows = document.querySelectorAll('#wrapper .rows'); const frozenClos = document.querySelectorAll('#wrapper .clos'); const loadMore = document.querySelectorAll('#wrapper .loadMore'); that.X = this.x that.Y = this.y frozenCrosses.forEach((el) => { el.style.transform = `translate(${ this.x}px, ${ this.y}px, 0px)` }) frozenRows.forEach((el) => { el.style.transform = `translate(0px, ${ this.y}px, 0px)` }) frozenClos.forEach((el) => { el.style.transform = `translate(${ this.x}px, 0px, 0px)` }) loadMore.forEach((el) => { el.style.transform = `translate(0px, ${ this.y}px, 0px)` }) } function _onPullUpLoad() { // 上拉加载函数 if(!that.flag){ //获取数据操作.... that.$nextTick(()=>{ const frozenCrosses = document.querySelectorAll('#wrapper .cross'); const frozenRows = document.querySelectorAll('#wrapper .rows'); const frozenClos = document.querySelectorAll('#wrapper .clos'); const loadMore = document.querySelectorAll('#wrapper .loadMore'); frozenCrosses.forEach((el) => { el.style.transform = `translate3d(${ that.x}px, ${ that.y}px, 0px)` }) frozenRows.forEach((el) => { el.style.transform = `translate3d(0px, ${ that.y}px, 0px)` }) frozenClos.forEach((el) => { el.style.transform = `translate3d(${ that.x}px, 0px, 0px)` }) loadMore.forEach((el) => { el.style.transform = `translate3d(0px, ${ that.y}px, 0px)` }) }) that.scroller.finishPullUp() that.scroller.refresh() } } this.scroller.on('scroll',_onScroll) this.scroller.on('scrollEnd',_onScroll) this.scroller.on('pullingUp',_onPullUpLoad) this.scroller.on('beforeScrollStart',()=>{ setTimeout(()=>{ this.scroller.refresh() },20) })},mounted(){ this.$nextTick(()=>{ this._init() }) }
转载地址:https://blog.csdn.net/lese_demo/article/details/90287112 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
不错!
[***.144.177.141]2024年04月18日 22时28分46秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Vue监视---vue工作笔记0005
2019-04-26
Vue条件渲染---vue工作笔记0008
2019-04-26
Vue事件处理_vue的事件处理超级方便_功能强大---vue工作笔记0011
2019-04-26
Vue表单数据自动收集---vue工作笔记0012
2019-04-26
Vue生命周期---vue工作笔记0013
2019-04-26
C++_类和对象_对象特性_构造函数的分类以及调用---C++语言工作笔记041
2019-04-26
C++_类和对象_对象特性_拷贝构造函数调用时机---C++语言工作笔记042
2019-04-26
C++_类和对象_对象特性_构造函数调用规则---C++语言工作笔记043
2019-04-26
C++_类和对象_对象特性_深拷贝与浅拷贝---C++语言工作笔记044
2019-04-26
AndroidStudio_android中实现对properties文件的读写操作_不把properties文件放在assets文件夹中_支持读写---Android原生开发工作笔记238
2019-04-26
弹框没反应使用Looper解决_the caller should invoke Looper.prepare() and Looper.loop()---Android原生开发工作笔记239
2019-04-26
Command line is too long. Shorten command line for Application---微服务升级_SpringCloud Alibaba工作笔记0067
2019-04-26
C++_类和对象_对象特性_初始化列表---C++语言工作笔记045
2019-04-26