Vue 表格循环滚动,鼠标移入暂停,移出继续滚动

简单例子:

<template> 中的代码:

<div 
  id="chart"
  ref="chart"
  class="table-body"
  @mouseenter="tableMouseOver"
  @mouseleave="tableMouseOut"
>
  <div class="row" v-for="(item,index) in tableList" :key="index">
    <div class="item">{{item.name}}</div>
    <div class="item">{{item.value}}</div>
    <div class="item">{{item.times}}</div>
  </div>
</div>

 data() 中的代码:

data() {
  return {
    tableList: [
      { name: "潘家小镇电影馆",value:"50", times: "2022-05-02" },
      { name: "党员活动",value:"38", times: "2022-08-01" },
      { name: "潘家小镇美丽游",value:"120", times: "2022-08-23" },
    ],
    //定时器名称
    timers: null,
  };
},

methods: {} 中的代码:

//滚动
tableScroll() {
  let that = this;
  clearInterval(this.timers);
  this.timers = setInterval(() => {
    let ContScroll = that.$refs.chart;
    //获取当前滚动上去的高度
    that.currentScrollTop = parseInt(ContScroll.scrollTop);
    //获取容器可视化高度
    let currentBoxHeight = parseInt(ContScroll.scrollHeight);
    if (
      currentBoxHeight - ContScroll.offsetHeight <=
      that.currentScrollTop
    ) {
      // 从头开始滚动
      // 暂停滚动,让"近30天流出人员去向地及数量"列表开始滚动
      that.currentindex = 0;
      ContScroll.scrollTo(0, 0);
    } else {
      that.currentindex++;
      ContScroll.scrollTo({ top: that.currentindex, left: 0 });
    }
  }, 100);
},
// 鼠标移出
tableMouseOut() {
  if (this.isScroll) {
    this.tableScroll();
    let ContScroll = this.$refs.chart;
    //获取当前滚动上去的高度
    this.currentindex = parseInt(ContScroll.scrollTop);
  }
},
// 鼠标移入
tableMouseOver() {
  clearInterval(this.timers);
},

beforeDestroy() {} 中的代码:

beforeDestroy() {
  clearInterval(this.timers);
}

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值