监听element-ui table滚动事件的代码示例


当前第2页 返回上一页

绑定监听事件

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

mounted() {

    // 获取需要绑定的table

    this.dom = this.$refs.table.bodyWrapper

    this.dom.addEventListener('scroll', () => {

        // 滚动距离

        let scrollTop = this.dom.scrollTop

        // 变量windowHeight是可视区的高度

        let windowHeight = this.dom.clientHeight || this.dom.clientHeight

        // 变量scrollHeight是滚动条的总高度

        let scrollHeight = this.dom.scrollHeight || this.dom.scrollHeight

        if (scrollTop + windowHeight === scrollHeight) {

            // 获取到的不是全部数据 当滚动到底部 继续获取新的数据

            if (!this.allData) this.getMoreLog()

            console.log('scrollTop', scrollTop + 'windowHeight', windowHeight + 'scrollHeight', scrollHeight)

        }

    })

}

获取到新的数据后,调整滚动条的位置

1

2

3

4

5

getMoreLog() {

    ...

    this.dom.scrollTop = this.dom.scrollTop - 100

    ...

}

结语:至此我们已经完成了对table的绑定!

本篇文章到这里就已经全部结束了,更多其他精彩内容可以关注PHP中文网的JavaScript视频教程栏目!

以上就是监听element-ui table滚动事件的代码示例的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

javascript中判断变量是否为数字的3种方法(附代码)

javascript怎么禁止缓存

html怎么加入js

javascript怎么删除 tr

javascript开发者非常有用的10个奇淫巧计

javascript日期格式如何转换成年月日

javascript怎么类型转换

10 种快速优化 web 性能的手段(分享)

原来es6 module还可以这样用!(备忘单)

javascript高阶函数的用法介绍

更多相关阅读请进入《javascript》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...