scroll到页面顶部 和 element ui table scrollTop 滚动到行头

本文详细介绍了如何使用Element UI中的Table组件实现滚动到指定行、页面顶部以及实时获取滚动条位置的方法。通过具体代码示例,读者可以学习到如何利用$nextTick和监听scroll事件来完成这些操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<el-table ref="multipleTable"
 ......>
      <slot></slot>
</el-table>

一、table滚动到行头

this.$nextTick(() => {
          this.$refs.multipleTable.bodyWrapper.scrollTop = 0;
})

滚动到最后一行:
this.$nextTick(() => {
    this.$refs.multipleTable.bodyWrapper.scrollTop = this.$refs.multipleTable.bodyWrapper.scrollHeight;
})

 二、页面顶部

<div class="scrollbar" ref="viewBox">
          <slot></slot>
</div>
<style>
.scrollbar {
  overflow-y: auto;
}
</style>

 

this.$refs.viewBox.scrollTop = 0;

三、实时获取scroll value 

<div class="flex-1 ev-scrollbar" ref="tableViewBox">
          <slot></slot>
        </div>

mounted(){
      let box = this.$refs['tableViewBox'];
      box.addEventListener('scroll', () => {
        console.log(" scroll " + this.$refs.tableViewBox.scrollTop)
      }, false);
    },

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值