npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ozo/masonry

v1.0.25

Published

intro component

Downloads

42

Readme

@ozo/masonry

基于 react 的瀑布流组件

dataTransfer

提供 dataTransfer 方法,提前转换数据格式,以满足组件需要。

参数说明:

/**
 * @param {Array} arr 转换前的数据
 * @param {Number} cols 列数,默认2
 * @param {Number} gutter 槽宽,默认10px
 * @param {Object} extra 其他扩展属性,{
 *          viewWidth, // 瀑布流view宽度,默认 414
 *          viewHeight, // 瀑布流view高度,默认 736
 *          addHeight, // 额外高度,容器中除图片外的高度
 *          maxHeight, // 子项最大高度,避免流末尾过度参差不齐
 *          imgPattern, // 图片尺寸匹配模式,默认为path,query(参数带宽高)、path(地址带宽高)、other(预加载获取宽高)
 *          force, // 强制重新计算所有值
 *      }
 * @returns {Array} 转换后的集合
 */
import Masonry, { dataTransfer } from '@ozo/masonry';

// 同步模式
const data = dataTransfer(getElements(), cols, gutter, {
    viewWidth
    viewHeight,
    addHeight,
    maxHeight,
});

// 异步模式:(采用 other加载时采用)
dataTransfer(getElements(), cols, gutter, {
    viewWidth
    viewHeight,
    addHeight,
    maxHeight,
}).then((data) => {
    this.setState({ data });
});

为优化加载,建议图片地址满足规范之一:

  • fetch-接口对象中返回宽高,如{src="xxx.jpg",width:300,height: 500},宽高的 key 只识别 width 或 height,不一致时,需要提前转换;
  • query-参数带宽高,如xxx.jpg?w=300&h=500
  • path-地址带宽高,如xxx/300/500.jpgxxx_300_500.jpg
  • other-如不满足则默认采用 other-预加载获取宽高,效果不佳。

返回值说明:

{
    ...原始数据项,
    imgWidth,
    imgHeight,
    imgRatio,
    width,
    height,
    ratio,
    viewWidth,
    viewHeight,
    gutter,
}

API

Masonry

| 参数名 | 说明 | 必填 | 类型 | 默认值 | 备注 | | ----------------- | :---------------------------------------------------------------------------------------------------------------------: | :--: | :--------------------------------------------: | :--------------------------------: | ---- | | className | 瀑布流容器样式类 | :x: | String | '' | | cols | 列数 | :x: | Number | 2 | | data | 数据源 | :x: | Object | {} | | gutter | 列间槽宽 | :x: | Number | 10 | | itemRender | 子项渲染方法,(item, style)=>{ return <自定义组件 />; } | :x: | Function | null | | itemStyle | 子项style样式 | :x: | Object | {} | | lazyLoadProps | 图片懒加载的属性集合,{ offset, 相对于当前元素顶部的提前加载偏移 }, 详情参见 https://github.com/twobin/react-lazyload | :x: | Object | { offset: window.screen.height } | | maxScreen | virtualized模式下,指定最大显示多少屏,默认为4 | :x: | Number | 4 | | onClick | 子项单击回调 | :x: | Function | null | | onScroll | 容器内滚动回调 | :x: | Function | null | | renderType | 渲染类型: 普通流(ok)、定位流(ok)、CSS多列流(测试中)、网格流(测试中) | :x: | Enum('normal', 'position', 'column', 'grid') | 'position' | | scrollTop | 设置初始滚动值,默认为0,仅首次加载时生效 | :x: | Number | 0 | | style | 瀑布流容器style样式 | :x: | Object | {} | | theme | 主题风格类型:扁平flat、立体shadow | :x: | Enum('shadow', 'flat') | 'shadow' | | type | 瀑布流类型:纵向(ok)、横向(暂未支持) | :x: | Enum('vertical', 'horizontal') | 'vertical' | | virtualized | 是否采用虚拟滚动 | :x: | Boolean | false |

Piece

| 参数名 | 说明 | 必填 | 类型 | 默认值 | 备注 | | ----------------- | :---------------------------------------------------------------------------------------------------------------------: | :--: | :---------: | :--------------------------------: | ---- | | className | 自定义样式类名 | :x: | String | '' | | data | 子项数据源 | :x: | Object | {} | | isPosition | 是否绝对定位,与Masonry组件的renderType一致: false:普通流、网格流,true:定位流 | :x: | Boolean | false | | lazyLoadProps | 图片懒加载的属性集合,{ offset, 相对于当前元素顶部的提前加载偏移 }, 详情参见 https://github.com/twobin/react-lazyload | :x: | Object | { offset: window.screen.height } | | style | 自定义样式 | :x: | Object | {} | | titleNode | 自定义title节点 | :x: | ReactNode | null |

ScrollView

实时返回 scrollTop,兼容移动端,默认开启了节流 | 参数名 | 说明 | 必填 | 类型 | 默认值 | 备注 | | -------------- | :----------------------------------------: | :----------------: | :--------: | :----: | ---- | | className | 瀑布流容器样式类 | :x: | String | '' | | delay | 滚动修正触发延迟时间,默认为16.7ms | :x: | Number | 16.7 | | onScroll | 容器内滚动回调 | :white_check_mark: | Function | | | scrollTop | 设置初始滚动值,默认为0,仅首次加载时生效 | :x: | Number | 0 | | scrollable | 是否可滚动 | :x: | Boolean | true | | style | 瀑布流容器style样式 | :x: | Object | {} |