1.0.5 • Published 11 months ago

react-waterfall-clover v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

react-waterfall-clover

React图片瀑布流

特性

  • 自定义节点渲染
  • 自适应图片大小
  • 缓冲高度

react-waterfall

使用

yarn add react-waterfall
import { Random } from "mockjs";
import React, { useMemo } from "react";
import "./app.css";
import { Waterfall } from "react-waterfall-clover";

export default function App() {
  const source = useMemo(
    () =>
      Array(30)
        .fill("")
        .map((_, i) => ({
          url: Random.image(
            `${Math.floor(Math.random() * 300)}x${Math.floor(
              Math.random() * 300
            )}`
          ),
        })),
    []
  );
  console.log("source",source);
  
  return (
    <>
      <Waterfall
        className="container"
        col={2}
        dataSource={source}
        colWidth={0}
        onScroll={(e) => {
          console.log("滚动", e);
        }}
        renderItem={(item, index) => (
          <div>
            <img src={item.url} key={index} alt={item} />
            <div>
              <span>666666</span>
            </div>
          </div>
        )}
      />
    </>
  );
}

props

prop类型默认必要描述
dataSourceany[][]true数据源
colnumber3false列数
fieldNamestringurlfalse图片字段名
colWidthnumber自适应false列宽度,默认根据列数自适应宽度
spacenumber | number[]10false间隙
extraItemHeightnumber0falseitem额外参与计算高度
renderItem(item: any, index: number) => JSX.Element-false自定义节点
onScrollHTMLDivElement-false容器滚动事件

colWidth

单列宽度不传,默认自动计算宽度

注: 请不要在 Waterfall 设置 paddingmargin 会影响列宽的计算准度

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago