react+antd+css animation实现表格滚动并解决不生效问题

今天的需求是做一个表头固定,数据自动滚动的表格,目前使用了animation,但是遇到一些问题,记录一下。

 componentDidMount() {
        // 滚动  (在数据请求回来后再计算高度,否则计算不准确)
          this.carousel = document.querySelector(".ant-carousel")
      this.carousel.style.overflow = "hidden"
      this.carouselBody = document.querySelector(".Descriptions")
      const carouselh = this.carousel.clientHeight
      const carouselBodyh = this.carouselBody.scrollHeight
      this.carouselBodyDiff = carouselBodyh - carouselh
      console.log(this.carousel, this.carouselBody, carouselh, carouselBodyh, this.carouselBodyDiff)
      if (this.carouselBodyDiff > 0) {
        this.styleIndex2 = document.styleSheets[0]
          .insertRule(`@keyframes r{
        0%{
          top:0;
        }
        100%{
          top:-${this.carouselBodyDiff}px;
        }
      }`);
        this.carouselBody.style.animation = "r 10s linear 1s infinite ";
        this.carouselBody.style.position = "relative"
      }
        }

    }
    render() {
        const ProjectInfo = this.props.ProjectInfo
        const data = [];
      ProjectInfo.map((i, index) => {
            data.push({
                key: i.id,
                deptName: i.Name,
                projectName: i.proName,
                level: i.le,
                delayDays: i.day
            });
        })
        return (
            <div style={{ height: "100%" }} className='box'> <Table
                columns={columns}
                dataSource={data}
                pagination={false}
                scroll={{
                    y: this.state.y,
                }}
            /></div>

        )
    }
}

this.carouselBody.style.position = “relative”
关键点就在这,一定要确定position = “relative”,否则不生效

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
React,使用Ant Design的Table组件,在表格添加操作列并结合Dropdown和Menu组件可以实现更丰富的交互效果。 首先,我们需要导入相关的组件和样式: ```jsx import { Table, Dropdown, Menu, Button } from 'antd'; import { DownOutlined } from '@ant-design/icons'; import 'antd/dist/antd.css'; ``` 然后,在表格的columns定义操作列,并使用Dropdown和Menu组件来定制操作菜单: ```jsx const columns = [ ...其他列定义, { title: '操作', key: 'action', render: (text, record) => ( <Dropdown overlay={menu}> <Button> 操作 <DownOutlined /> </Button> </Dropdown> ), }, ]; const menu = ( <Menu> <Menu.Item key="1"> <a target="_blank" rel="noopener noreferrer" href="#"> 编辑 </a> </Menu.Item> <Menu.Item key="2"> <a target="_blank" rel="noopener noreferrer" href="#"> 删除 </a> </Menu.Item> </Menu> ); ``` 以上代码,columns定义了表格的列,其操作列使用render属性来渲染。在render方法,我们使用Dropdown组件来包裹Button,并将Menu作为overlay传入。 menu定义了操作菜单的内容,其使用Menu.Item来定义菜单项,通过设置key属性来区分不同的菜单项。菜单项可以是一段文本或者其他React元素,这里我们使用a标签来模拟菜单项的操作。 最后,在Table组件将columns配置为表格的列: ```jsx <Table columns={columns} dataSource={data} /> ``` 以上是在React使用Ant Design的Table组件添加操作列并结合Dropdown和Menu的写法,通过这种方式,我们可以方便地在表格定制各种操作的菜单。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值