一个用于在网格布局中无限排列卡片元素(包括内容)的模块。
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
$ npm install --save @egjs/infinitegridimport { MasonryInfiniteGrid } from "@egjs/infinitegrid";
const ig = new MasonryInfiniteGrid(".container", { gap: 5 });
<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(`
`);
}
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();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.data-grid-width and data-grid-height attributes, the size of self, child image, and video elements is automatically adjusted until loading is complete.data-grid-skip="true" attribute, you can omit it even if there are images in itself and child image, and video elements.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();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.
isEqualSize assumes all items are equal. But if there are more than two size-groups, use data-grid-size-group.
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.
| Package | Version | Description |
|---|---|---|
| @egjs/infinitegrid | Vanilla Module of InfiniteGrid | |
| @egjs/ngx-infinitegrid | Angular port of @egjs/infinitegrid | |
| @egjs/react-infinitegrid | React port of @egjs/infinitegrid | |
| @egjs/vue-infinitegrid | Vue.js@2 port of @egjs/infinitegrid | |
| @egjs/vue3-infinitegrid | Vue.js@3 port of @egjs/infinitegrid | |
| @egjs/svelte-infinitegrid | Svelte port of @egjs/infinitegrid |
| 9+(With polyfill), 11+ for Angular & Svelte | Latest | Latest | Latest | 7+ | 4+ |
Check our Demos.
See Documentation page.
See CONTRIBUTING.md.
Please file an Issue.
See our Roadmap.
@egjs/infinitegrid is released under the MIT license.
…暂无开放 Issues,或尚未同步最近议题。