监听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中的延迟加载

聊聊javascript人脸识别技术

javascript是啥

javascript对象的定义方法有哪些

javascript怎么设置元素居中

javascript为什么没有权限

javascript如何实现跳转新页面

五个超好用的array.from()用途(详解)

angular实现只执行正在开发的新单元测试

javascript怎么移除li

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




打赏

取消

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

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

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

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

评论

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