首页 > 其他分享 >react + antd table列表自动滚动

react + antd table列表自动滚动

时间:2023-05-08 14:57:38浏览次数:38  
标签:滚动 timer react dataSource antd autoScroll table

/**
* @file: table列表自动滚动,鼠标划入滚动暂停,鼠标划出滚动继续
*/
const [dataSource, setDataSource] = useState([])

const [timer, setTimer] = useState()

useEffect(() => {
  if (dataSource.length) {
    autoScroll(dataSource)
  }
  return () => clearInterval(timer);
}, [dataSource])

const autoScroll = (data) => {
  let v = document.getElementsByClassName('antd-table-body')[0];
  if (data.length > 5) { // 5可以根据各自的列表高度替换
    let time = setInterval(() => {
      v.scrollTop++;
      if (Math.ceil(v.scrollTop) >= parserFloat(v.scrollHeight - v.clientHeight)) { // 滚动条到底后重新开始
        v.scrollTop = 0;
      }
    }, 50)
    setTimer(timer);
  }
}

return (
  <div
    onMouseEnter={() => {
      clearInterval(timer)
    }}
    onMouseLeave={() => {
      autoScroll(dataSource)
    }}
  >
    <Table
      dataSource={dataSource}
      scroll={{ y: 320 }}
      columns={...}
    />
  </div>
)
  

 

标签:滚动,timer,react,dataSource,antd,autoScroll,table
From: https://www.cnblogs.com/lou-0820/p/17381746.html

相关文章

  • [Warning] World-writable config file '/etc/my.cnf' is ignored
    告警信息,全局读写配置文件,那么就把权限调整小。 ......
  • django-datatable-view==0.9.0 Django 3.1.3: ImportError:无法导入名称'FieldDoesNot
    问题答案来自于:https://cloud.tencent.com/developer/ask/sof/891274源码:fromdjango.db.models.fieldsimportFieldDoesNotExist 替换:fromdjango.core.exceptionsimportFieldDoesNotExist......
  • 无界AI绘画基础教程,和Midjourney以及Stable Diffusion哪个更好用?
    本教程收集于:AIGC从入门到精通教程汇总简单的总结Midjourney,StableDiffusion,无界AI的区别?Midjourney,收费,上手容易,做出来高精度的图需要自己掌握好咒语。咒语写不好,像是抽奖。里面的模型基本都是大模型,小模型太少,需要一些辅助机器人或者辅助操作保持画风的一致。StableDiffus......
  • Reactor接口之五
    defaultIfEmpty@TestpublicvoidtestDefaultIfEmpty(){Flux.range(1,10).defaultIfEmpty(30).subscribe(System.out::println);}@TestpublicvoidtestDefaultIfEmpty1(){Flux.empty().defaultIfEmpty(30)......
  • [React Typescript] ComponentProps
    Blog:https://www.totaltypescript.com/react-component-props-type-helper GetanyProptypefromhtmlelement:import{ComponentProps}from"react";typeButtonProps=ComponentProps<"button">; GetpropstypefromaComponen......
  • Reactor接口之四
    interval@TestpublicvoidtestInterval(){CountDownLatchcountDownLatch=newCountDownLatch(1);Flux.range(1,10).zipWith(Flux.interval(Duration.ofSeconds(1))).subscribe(System.out::println,null,countDownLatch::countD......
  • Reactor接口之三
    defer@TestpublicvoidtestDefer(){Flux.defer(()->{returnFlux.range(0,10);}).subscribe(System.out::println);}输出0到9。defer每次对结果Flux进行订阅时,懒惰地提供发布服务。因此实际的源实例化会推迟到每次订阅时。collect@Te......
  • treeTable
    [color=red]jqgrid中文官网[/color]:http://blog.mn886.net/jqGrid/http://zhaozhi3758.iteye.com/blog/1399229关键:http://chenjumin.iteye.com/blog/419522关键2:http://panyongzheng.iteye.com/blog/1918070全面的东西:http://www.trirand.com/blog......
  • mac M2 mule esb 3.9 Bad CPU type in executable
    启动直接报错linux由于是amd64linux版本不支持cpu指令集找到合适的theJavaServiceWrapper做转换https://wrapper.tanukisoftware.com/doc/english/download.jsp#stable下载解压warapper.jar移动并改名lib/bootwarapper移动并改名lib/boot/exec改名......
  • Reactor接口之二
    merge@TestpublicvoidtestMerge(){Flux.merge(Flux.just(1,2,3),Flux.range(5,6)).subscribe(System.out::println);}merge将多个Flux合并成一个Flux。 @TestpublicvoidtestMerge1(){Flux.range(1,5).mergeWith(Flux.just(8,9......