瀑布流布局 autoresponsive-react

顾喜
2023-12-01

1、安装

$ npm i autoresponsive-react --save

2、使用

import AutoResponsive from "autoresponsive-react";
   componentDidMount() {
        this.setState({
            containerWidth: (document.body.clientWidth || document.documentElement.clientWidth) - 322
        });
    }
  getAutoResponsiveProps = () => {
        return {
            itemMargin: 10,
            containerWidth: this.state.containerWidth,//容器总宽度
            itemClassName: 'productListItem',
            gridWidth: 20,//列宽
            transitionDuration: '.5'//过度动画时常
        };
    };
<AutoResponsive {...this.getAutoResponsiveProps()}>
	{
		    data.map((item, index) => {
			      const {height, width, path} = item._350;
			      let heights = (item.cmtStar > 0 || item.cmtCount > 0) ? 124 : 88;
			      return (
			          <div 
			          		key={item.object_id} 
			          		style={{width: 286, height: (286 * height / width) + heights}} 
			          		className="productListItem pr"
			          >
			             <div>todo 你想要展示的内容</div>
			         </div>
		         )
		  })
	}
</AutoResponsive>
 类似资料: