利用better-scroll插件做移动端table可上下左右滑动且固定表头和列
发布日期:2022-02-19 23:50:23 浏览次数:35 分类:技术文章

本文共 3825 字,大约阅读时间需要 12 分钟。

上下左右滑动时固定表头、列&上拉加载

思路

显示结构
.cross .row .row
data.clos data data
data.clos data data
思路步骤
  1. 配置BScroll配置项
  2. 声明BScrollscroll事件函数:onScroll,在里面取得所有.cross/.row/.clos元素,并对每个元素添加transform样式,且记录实时滚动的x,y值。.crossx,y实时同步;.rowx为0,y同步;.closx同步,y为0。
  3. 声明BScrollpullUpLoad事件(上拉加载)函数: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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:记录我的学习笔记
下一篇:记录在vue-edu练习项目上遇到的问题

发表评论

最新留言

不错!
[***.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
ES6-ES11新特性_ECMAScript_简单介绍---JavaScript_ECMAScript工作笔记001 2019-04-26
ES6-ES11新特性_ECMAScript相关名词介绍_---JavaScript_ECMAScript工作笔记002 2019-04-26
ES6新特性_let变量声明以及声明特性---JavaScript_ECMAScript_ES6-ES11新特性工作笔记003 2019-04-26
Sharding-Sphere,Sharding-JDBC_介绍_Sharding-Sphere,Sharding-JDBC分布式_分库分表工作笔记001 2019-04-26
Sharding-Sphere,Sharding-JDBC_分库分表介绍_Sharding-Sphere,Sharding-JDBC分布式_分库分表工作笔记002 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_java.util.ConcurrentModificationException---Android原生开发工作笔记237 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
AndroidStudio_android实现双击_3击_监听实现---Android原生开发工作笔记240 2019-04-26
C++_类和对象_对象特性_初始化列表---C++语言工作笔记045 2019-04-26