@frontity/lazyload

中文文档
1.0.12发布于 2018/10/26MITCommonJS近 30 天下载 2393

Lazy load component for React, with fastdom

原始使用文档

LazyLoad

An easy-to-use component that loads its content in a lazy way.

It uses fastdom to get the values of the css properties and avoid possible layout/reflow trashing.

Also, visibility of lazy load components is calculated using window as reference by default. You can also use component inside scrolling container, such as div with scrollbar, but if you want to do that, the container element must be explicitly defined through the container prop.

Based on React Lazy Load.

Installation

npm i @frontity/lazyload

Props

container

Type Element|Window

A reference to a DOM element used for calculating visibility of LazyLoad components. The default is window.

offset

Type: Number|String Default: 0

Aliases: threshold

The offset option allows you to specify how far below, above, to the left, and to the right of the viewport you want to begin displaying your content. If you specify 0, your content will be displayed as soon as it is visible in the viewport, if you want to load 1000px below or above the viewport, use 1000.

offsetVertical

Type: Number|String Default: offset's value

The offsetVertical option allows you to specify how far above and below the viewport you want to begin displaying your content.

offsetHorizontal

Type: Number|String Default: offset's value

The offsetHorizontal option allows you to specify how far to the left and right of the viewport you want to begin displaying your content.

offsetTop

Type: Number|String Default: offsetVertical's value

The offsetTop option allows you to specify how far above the viewport you want to begin displaying your content.

offsetBottom

Type: Number|String Default: offsetVertical's value

The offsetBottom option allows you to specify how far below the viewport you want to begin displaying your content.

offsetLeft

Type: Number|String Default: offsetVertical's value

The offsetLeft option allows you to specify how far to left of the viewport you want to begin displaying your content.

offsetRight

Type: Number|String Default: offsetVertical's value

The offsetRight option allows you to specify how far to the right of the viewport you want to begin displaying your content.

throttle

Type: Number|String Default: 250

The throttle is managed by an internal function that prevents performance issues from continuous firing of scroll events. Using a throttle will set a small timeout when the user scrolls and will keep throttling until the user stops. The default is 250 milliseconds.

debounce

Type: Boolean Default: true

By default the throttling function is actually a debounce function so that the checking function is only triggered after a user stops scrolling. To use traditional throttling where it will only check the loadable content every throttle milliseconds, set debounce to false.

height

Type: String|Number

The height option allows you to set the element's height even when it has no content.

width

Type: String|Number

The width option allows you to set the element's width even when it has no content.

onContentVisible

Type Function

A callback function to execute when the content appears on the screen.

async (experimental)

Type boolean

Indicates if lazyload content are mounted asychronously, using the React asynchronous rendering.

版本与发布记录

@frontity/lazyload 共发布 14 个版本,首次发布于 2018/04/25;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.12latest2018/10/268 年前
2.0.1next2018/10/168 年前
1.0.112018/10/168 年前
2.0.02018/10/108 年前
1.0.102018/10/108 年前
1.0.92018/10/108 年前

关于 @frontity/lazyload 的常见问题

@frontity/lazyload 是什么?

Lazy load component for React, with fastdom

如何安装 @frontity/lazyload?

在项目目录运行 npm install @frontity/lazyload,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^16.5.0)、react-dom(^16.5.0)、prop-types(^15.5.8)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@frontity/lazyload 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/frontity__lazyload 是否存在。

@frontity/lazyload 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@frontity/lazyload 可以商用吗?

@frontity/lazyload 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@frontity/lazyload 的下载量有多少?

根据 npm 官方下载统计,@frontity/lazyload 在 2026/10/16 – 2026/11/14 这 30 天内被下载 2,393 次,日均约 80 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@frontity/lazyload 还在维护吗?

最新版本 1.0.12 发布于 2018/10/26(8 年前);至今共发布 14 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/04/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。