@egjs/infinitegrid

中文文档
4.13.1发布于 2026/10/30MITTypeScriptESM + CJS近 30 天下载 8.3万

A module used to arrange elements including content infinitely according to grid type. With this module, you can implement various grids composed of different card elements whose sizes vary. It guarantees performance by maintaining the number of DOMs the

原始使用文档
文档目录19 节
  1. Demo / Documentation / Other components
  2. ✨ Features
  3. 📖 Articles
  4. ⚙️ Installation
  5. 🏃 Quick Start
  6. Use Faster & Lazy Rendering
  7. Detect resize of Container & Children
  8. Pre-guess size for performance or invisible items.
  9. What if all items were the same size?
  10. What if a size group exists?
  11. What if all items don't change size?
  12. 📦 Packages
  13. 🌐 Supported Browsers
  14. 📼 Demos
  15. 📖 Documentation
  16. 🙌 Contributing
  17. 📝 Feedback
  18. 🛣️ Roadmap
  19. 📜 License

InfiniteGrid Logo
@egjs/infinitegrid

version npm weekly downloads npm bundle size (scoped) Github actions Coveralls github GitHub

Angular React Vue Svelte

Demo / Documentation / Other components

A module used to arrange elements including content infinitely according to grid type. With this module, you can implement various grids composed of different card elements whose sizes vary. It guarantees performance by maintaining the number of DOMs the module is handling under any circumstance
📱💻🖥

Supported Frameworks
AngularJS   React   Vue.js   Svelte


✨ Features

  • Use it in a framework you like.
    • We supports all major JS frameworks like React, Vue, Angular
  • Restore state like position and active slide with persist
  • Supports both Desktop & Mobile
  • Support Dynamic Options
  • Rich API

📖 Articles

⚙️ Installation

npm

$ npm install --save @egjs/infinitegrid

CDN

🏃 Quick Start

HTML

<div class="container"></div>

ES Modules

import { MasonryInfiniteGrid } from "@egjs/infinitegrid";

const ig = new MasonryInfiniteGrid(".container", { gap: 5 });

With CDN

<!-- Packaged with all dependencies -->
<!-- https://naver.github.io/egjs-infinitegrid/release/latest/dist/infinitegrid.min.js -->
<script src="https://unpkg.com/@egjs/infinitegrid/dist/infinitegrid.min.js"></script>
var ig = new InfiniteGrid.MasonryInfiniteGrid(".container", { gap: 5 });
import { MasonryInfiniteGrid } from "@egjs/infinitegrid";

function getItems(nextGroupKey, count) {
  const nextItems = [];

  for (let i = 0; i < count; ++i) {
    const num = nextGroupKey * count + i;
    nextItems.push(`<div class="item"></div>`);
  }
  return nextItems;
}
const ig = new MasonryInfiniteGrid(".container", {
  gap: 5,
});

ig.on("requestAppend", (e) => {
  const nextGroupKey = (+e.groupKey || 0) + 1;

  ig.append(getItems(nextGroupKey, 10), nextGroupKey);
});
ig.renderItems();

Use Faster & Lazy Rendering

  • When the loading="lazy" or data-grid-lazy="true"(external lazy loading) attribute is used, Rendering of the items occurs immediately. When items are loaded, they are rendered sequentially.
<img src="..." />
<img src="..." />
<img src="..." loading="lazy" />
<img data-grid-lazy="true" />
  • If you use data-grid-width and data-grid-height attributes, the size of self, child image, and video elements is automatically adjusted until loading is complete.
<div data-grid-width="100" data-grid-height="100">
   <img src="..." />
   <img src="..." />
   <img src="..." />
</div>
  • If you use data-grid-skip="true" attribute, you can omit it even if there are images in itself and child image, and video elements.
<div data-grid-skip="true">
   <img src="..." />
   <img src="..." />
   <img src="..." />
</div>

Detect resize of Container & Children

InfiniteGrid calculates the size of container and children by window resizing event. However, even if the size of the window does not change, the size of the event container and children can change. Most of the first rendering issues are also like this.

In this case, I recommend ResizeObserver for you.

Provides useResizeObserver option to detect size change of container and observeChildren option to detect size change of children.

import { MasonryInfiniteGrid, JustifiedInfiniteGrid, FrameInfiniteGrid, PackingInfiniteGrid } from "@egjs/infinitegrid";


// InfiniteGrid.MasonryInfiniteGrid
const grid = new MasonryInfiniteGrid(container, {
  gap: 5,
  useResizeObserver: true,
  observeChildren: true,
});

grid.renderItems();

Pre-guess size for performance or invisible items.

What if all items were the same size?

If you use the isEqualSize option, all items are considered to be the same size. Each resize only calculates the size of one item. Add data-grid-not-equal-size="true" attribute if there is an exceptional item whose size needs to be calculated while using isEqualSize.

<div class="item item1"></div>
<div class="item item1"></div>
<div class="item item1"></div>
<!--item2 is a different size than item1.-->
<div class="item item2" data-grid-not-equal-size="true"></div>

What if a size group exists?

isEqualSize assumes all items are equal. But if there are more than two size-groups, use data-grid-size-group.

<!--item1 has the same size.-->
<div class="item item1" data-grid-size-group="1"></div>
<div class="item item1" data-grid-size-group="1"></div>
<!--item2 has the same size.-->
<div class="item item2" data-grid-size-group="2"></div>
<div class="item item2" data-grid-size-group="2"></div>

What if all items don't change size?

If all items do not have a constant size, use the isConstantSize option. Resizing doesn't calculate the item's size. If you want to recalculate, use .updateItems(items, { useOrgResize: true }) method or .renderItems({ useOrgResize: true }) method.

📦 Packages

PackageVersionDescription
@egjs/infinitegridversionVanilla Module of InfiniteGrid
@egjs/ngx-infinitegridversionAngular Angular port of @egjs/infinitegrid
@egjs/react-infinitegridversionReact React port of @egjs/infinitegrid
@egjs/vue-infinitegridversionVue.js Vue.js@2 port of @egjs/infinitegrid
@egjs/vue3-infinitegridversionVue.js Vue.js@3 port of @egjs/infinitegrid
@egjs/svelte-infinitegridversionSvelte Svelte port of @egjs/infinitegrid

🌐 Supported Browsers

IEChromeFirefoxSafariiOSAndroid
9+(With polyfill), 11+ for Angular & SvelteLatestLatestLatest7+4+

📼 Demos

Check our Demos.

📖 Documentation

See Documentation page.

🙌 Contributing

See CONTRIBUTING.md.

📝 Feedback

Please file an Issue.

🛣️ Roadmap

See our Roadmap.

📜 License

@egjs/infinitegrid is released under the MIT license.

Copyright (c) 2015-present NAVER Corp.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

      

版本与发布记录

@egjs/infinitegrid 共发布 188 个版本,首次发布于 2017/04/26;过去 12 个月发布了 7 个版本。

版本发布日期距今
4.13.1latest2026/10/3014 天前
4.13.1-beta.5beta2026/10/2321 天前
4.13.1-beta.22026/02/039 个月前
4.13.1-beta.12026/02/039 个月前
4.13.1-beta.02026/01/219 个月前
4.13.02025/12/2910 个月前

关于 @egjs/infinitegrid 的常见问题

@egjs/infinitegrid 是什么?

A module used to arrange elements including content infinitely according to grid type. With this module, you can implement various grids composed of different card elements whose sizes vary. It guarantees performance by maintaining the number of DOMs the

如何安装 @egjs/infinitegrid?

在项目目录运行 npm install @egjs/infinitegrid,或使用 pnpm add / yarn add / bun add。

@egjs/infinitegrid 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@egjs/infinitegrid 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@egjs/infinitegrid 可以商用吗?

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

@egjs/infinitegrid 的下载量有多少?

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

@egjs/infinitegrid 还在维护吗?

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