Infinite Grid

A module used to arrange card elements including content infinitely on a gr...

README

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

  1. ``` sh
  2. $ npm install --save @egjs/infinitegrid
  3. ```

CDN

- jsDelivr: https://cdn.jsdelivr.net/npm/@egjs/infinitegrid/dist/
- unpkg: https://unpkg.com/@egjs/infinitegrid/dist/
- cdnjs: https://cdnjs.com/libraries/egjs-infinitegrid

🏃 Quick Start

HTML


  1. ``` html
  2. <div class="container"></div>
  3. ```

ES Modules

  1. ```ts
  2. import { MasonryInfiniteGrid } from "@egjs/infinitegrid";

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

With CDN

  1. ``` html
  2. <script src="https://unpkg.com/@egjs/infinitegrid/dist/infinitegrid.min.js"></script>
  3. ```

  1. ``` js
  2. var ig = new InfiniteGrid.MasonryInfiniteGrid(".container", { gap: 5 });
  3. ```


  1. ``` js
  2. import { MasonryInfiniteGrid } from "@egjs/infinitegrid";

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

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

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

  16.   ig.append(getItems(nextGroupKey, 10), nextGroupKey);
  17. });
  18. ig.renderItems();
  19. ```

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.
  1. ``` html
  2. <img src="..." />
  3. <img src="..." />
  4. <img src="..." loading="lazy" />
  5. <img data-grid-lazy="true" />
  6. ```
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.
  1. ``` html
  2. <div data-grid-width="100" data-grid-height="100">
  3.    <img src="..." />
  4.    <img src="..." />
  5.    <img src="..." />
  6. </div>
  7. ```

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.
  1. ``` html
  2. <div data-grid-skip="true">
  3.    <img src="..." />
  4.    <img src="..." />
  5.    <img src="..." />
  6. </div>
  7. ```

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.


  1. ``` js
  2. import { MasonryInfiniteGrid, JustifiedInfiniteGrid, FrameInfiniteGrid, PackingInfiniteGrid } from "@egjs/infinitegrid";


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

  9. grid.renderItems();
  10. ```

📦 Packages

|Package|Version|Description|
|:-----:|:-----:|:-----:|
|[**@egjs/infinitegrid**](https://github.com/naver/egjs-infinitegrid/blob/master/packages/infinitegrid/README.md)|version|Vanilla Module of InfiniteGrid||[**@egjs/ngx-infinitegrid**](https://github.com/naver/egjs-infinitegrid/blob/master/packages/ngx-infinitegrid/README.md)|version|Angular [Angular](https://angular.io/) port of @egjs/infinitegrid||[**@egjs/react-infinitegrid**](https://github.com/naver/egjs-infinitegrid/blob/master/packages/react-infinitegrid/README.md)|version|React [React](https://reactjs.org/) port of @egjs/infinitegrid||[**@egjs/vue-infinitegrid**](https://github.com/naver/egjs-infinitegrid/blob/master/packages/vue-infinitegrid/README.md)|version|Vue.js [Vue.js@2](https://vuejs.org/v2/guide/index.html) port of @egjs/infinitegrid||[**@egjs/vue3-infinitegrid**](https://github.com/naver/egjs-infinitegrid/blob/master/packages/vue3-infinitegrid/README.md)|version|Vue.js [Vue.js@3](https://v3.vuejs.org/) port of @egjs/infinitegrid||[**@egjs/svelte-infinitegrid**](https://github.com/naver/egjs-infinitegrid/blob/master/packages/svelte-infinitegrid/README.md)|version|Svelte [Svelte](https://svelte.dev/) port of @egjs/infinitegrid|

🌐 Supported Browsers

|IE|Chrome|Firefox|Safari|iOS|Android|
|:---:|:---:|:---:|:---:|:---:|:---:|
|9+(With polyfill), 11+ for Angular & Svelte|Latest|Latest|Latest|7+|4+|

📼 Demos

Check our Demos.

📖 Documentation

See Documentation page.

🙌 Contributing


📝 Feedback

Please file an Issue.

🛣️ Roadmap

See our Roadmap.

📜 License

@egjs/infinitegrid is released under the MIT license.

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