🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

react-masonry-component3

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-masonry-component3

react 的瀑布流组件库,支持 columns 布局、弹性布局、绝对定位布局三种方法实现

latest
Source
npmnpm
Version
1.0.10
Version published
Weekly downloads
2
100%
Maintainers
1
Weekly downloads
 
Created
Source

React 瀑布流组件

  • 支持 2 种排列方向
  • 支持纵向排列
  • 支持横向排列(默认)
  • 支持按高度排序
  • 支持根据屏幕宽度自适应列数

组件文档地址

安装

npm i react-masonry-component2

纵向布局

direction='column'表示纵向布局。

import { Masonry } from 'react-masonry-component2'

export const MyComponent = (args) => {
  return (
    <Masonry
      direction='column'
      columnsCountBreakPoints={{
        1400: 5,
        1000: 4,
        700: 3,
      }}
    >
      <div></div>
      <div></div>
      <div></div>
    </Masonry>
  )
}

image.png

横向布局

direction='column'表示横向布局,默认横向布局。

import { Masonry, MasonryItem } from 'react-masonry-component2'

export const MyComponent = (args) => {
  return (
    <Masonry
      columnsCountBreakPoints={{
        1400: 5,
        1000: 4,
        700: 3,
      }}
    >
        <div></div>
        <div></div>
        <div></div>
    </Masonry>
  )
}

image.png

横向布局+高度排序

sortWithHeight 表示按照高度排序,选每列高度最小的添加元素。

import {Masonry, MasonryItem} from 'react-masonry-component2'

export const MyComponent = (args) => {
  return (
    <Masonry
      sortWithHeight
      columnsCountBreakPoints={{
        1400: 5,
        1000: 4,
        700: 3,
      }}
    >
      <MasonryItem height={200}>
        <div></div>
      </MasonryItem>
      <MasonryItem height={300}>
        <div></div>
      </MasonryItem>
      <MasonryItem height={400}>
        <div></div>
      </MasonryItem>
    </Masonry>
  )
}

image.png

横向布局+高度排序+绝对定位

useAbsolute 表示使用绝对定位实现瀑布流。

import {Masonry, MasonryAbsoluteItem} from 'react-masonry-component2'

export const MyComponent = (args) => {
  return (
    <Masonry
      useAbsolute
      sortWithHeight
      columnsCountBreakPoints={{
        1400: 5,
        1000: 4,
        700: 3,
      }}
    >
      <MasonryAbsoluteItem width={100} height={200}>
        <div></div>
      </MasonryAbsoluteItem>
      <MasonryAbsoluteItem width={100} height={300}>
        <div></div>
      </MasonryAbsoluteItem>
      <MasonryAbsoluteItem width={100} height={400}>
        <div></div>
      </MasonryAbsoluteItem>
    </Masonry>
  )
}

image.png

支持滚动自动加载更多的瀑布流

import MasonryScroll from "react-masonry-component2";
export const MyComponent = (args) => {
  return (
    <MasonryScroll
      preload={false}
      fetchApi={() =>
        new Promise((resolve, reject) => {
          setTimeout(() => {
            resolve(MockData.list);
          }, 500);
        })
      }
    ></MasonryScroll>
  );
};

支持预加载的瀑布流

import MasonryScroll from "react-masonry-component2";
export const MyComponent = (args) => {
  return (
    <MasonryScroll
      fetchApi={() =>
        new Promise((resolve, reject) => {
          setTimeout(() => {
            resolve(MockData.list);
          }, 500);
        })
      }
    ></MasonryScroll>
  );
};

Keywords

react

FAQs

Package last updated on 03 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts