Giter Site home page Giter Site logo

naver / egjs-infinitegrid Goto Github PK

View Code? Open in Web Editor NEW
1.9K 24.0 90.0 185.92 MB

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

Home Page: https://naver.github.io/egjs-infinitegrid/

License: MIT License

JavaScript 4.01% HTML 6.09% CSS 1.47% TypeScript 42.32% Vue 2.24% Svelte 1.22% Sass 0.55% MDX 42.10%
infinitegrid egjs masonry layout javascript dom-recycle react infinite grid vue

egjs-infinitegrid's Introduction

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

Angular React Vue Svelte

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

Package Version Description
@egjs/infinitegrid version Vanilla Module of InfiniteGrid
@egjs/ngx-infinitegrid version Angular Angular port of @egjs/infinitegrid
@egjs/react-infinitegrid version React React port of @egjs/infinitegrid
@egjs/vue-infinitegrid version Vue.js Vue.js@2 port of @egjs/infinitegrid
@egjs/vue3-infinitegrid version Vue.js Vue.js@3 port of @egjs/infinitegrid
@egjs/svelte-infinitegrid version Svelte Svelte 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

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's People

Contributors

arturovt avatar bang9 avatar beanmilk avatar daybrush avatar kode15333 avatar lcorb avatar malangfox avatar mixed avatar sculove avatar sh-cho avatar woodneck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

egjs-infinitegrid's Issues

add isTrust properties

Description

infiniteGrid 3.0 omits isTrusted property on append/prepend/change events

remove name in AMD

Description

If you use infinitegrid in AMD, you should use 'infiniteGrid' as named.

(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory(require("@egjs/component"));
	else if(typeof define === 'function' && define.amd)
		define("InfiniteGrid", ["@egjs/component"], factory);
	else if(typeof exports === 'object')
		exports["InfiniteGrid"] = factory(require("@egjs/component"));
	else
		root["eg"] = root["eg"] || {}, root["eg"]["InfiniteGrid"] = factory(root["eg"]["Component"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_5__) {

If you remove umdNamedDefine property, you can use something name.

(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory(require("@egjs/component"));
	else if(typeof define === 'function' && define.amd)
		define(["@egjs/component"], factory);
	else if(typeof exports === 'object')
		exports["InfiniteGrid"] = factory(require("@egjs/component"));
	else
		root["eg"] = root["eg"] || {}, root["eg"]["InfiniteGrid"] = factory(root["eg"]["Component"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_5__) {

Research IntersectionObserver spec

@sculove commented on Fri Apr 22 2016

Description

I think IntersectionObserver spec can use at infiniteGrid and visible.
Therefore, check this spec.
https://developers.google.com/web/updates/2016/04/intersectionobserver


@kishu commented on Fri Nov 18 2016

image

Intersection Observer API is good, but it is an experimental technology and not supported by most browsers. I want you to keep looking over time.

The implementation code for polyfill of this API(https://github.com/WICG/IntersectionObserver/tree/gh-pages/polyfill) is interesting. I will refer to it in the egjs conversion work.

provides container tagname

Description

when isOverflowScroll options is 'true', infiniteGrid create dom element.
this is div element.
but, user want to use other tags like 'ul' , 'ol', ...

InfinteGrid show x-boxs when Image is failed

Description

  • infiniteGrid should support failover feature when image loading is failed. (error code 404)
  • infiniteGrid should notify that the image loading is failed.

Interface

new eg.InfiniteGrid("#grid", {
    itemSelector: ".item"
}).on({
    "imageError": function(e) {
        // e.target: image element. - replace image element or src
        // e.item: item element. - If the item was previously deleted, this value is undefined.
    },
});

infiniteGrid resize bug

Description

if trigger resize event, items' length is doubled.
previous items are the same as the next items.
previous items are not show. next items are show after previous items.

Steps to check or reproduce

Make default demo for test case

Description

Make default demo for test case

  • GridLayout
  • JustifedLayout
  • FrameLayout
  • SquareLayout
  • PackingLayout
  • append
  • prepend
  • getStatus
  • setStatus
  • endableParallax
  • disableParallax
  • clear
  • vertical
  • horizontal

Steps to check or reproduce

Intent to apply CSS containment

@netil commented on Fri Aug 05 2016

Description

For some components, can be useuful improving rendering cost with CSS containment property.
https://developers.google.com/web/updates/2016/06/css-containment

Try to find if it's applicable.


@netil commented on Wed Nov 16 2016

There're many behavioural causing side effects.
When panels are fixed size is worth to apply, but there's no guarantee of external(ex. intentional trigger) layout transformation.

Try research and look for more practical use cases of that spec. keeping this issue for later.

Support parallax scrolling

Description

Support parallax scrolling.
If item has parallax class name and image is longer than the area surronding this, apply parallax scrolling.

Steps to check or reproduce

Use only option parallax.
Parallax's options have selector, strength, ...
selector option indicates the image to parallax scroll.
strength option indicates parallax scroll speed.

If item has not the image indicated selector, this item does not apply parallax scrolling.

var ig = new eg.InfiniteGrid(container, {
	parallax: true,
/*
default
{
	selector: "img",
	strength: 1,
*/
});

// or 
var ig = new eg.InfiniteGrid(container, {
	parallax: {
		selector: ".thumbnail", 
		strength: 1, // default 1
	},
});

Image is longer than the area(item)

.item {
	height: 400px;
	overflow:hidden;
}
img {
	height: 600px;
}

Surrounding area is images's parent node.

<div class="item">
	<img src="...." class="thumbnail">
</div>

2017-09-21 1 58 25

Parallax scrolling use transform level 1.
This is supported from IE9 or later, but use with a prefix.

update env files

Description

  • support release, changelog task
  • update dependency lib

fix start page for v3.0.0

Description

fix start page for v3.0.0

  • 5 Layouts
    • Demos in 5 Layouts
  • Projects

Steps to check or reproduce

provide layout interface

Description

provide layout interface
layout(groups: Group[], outline: number[]);
append(group: Group, outline: number[]): Group;
prepend(group: Group, outline: number[]): Group;
setViewport(width: number, height: number);

#32

Steps to check or reproduce

add demo for 3.0.0

Description

  1. each layout demo
  2. one row infinite demo
  3. two row infinite demo

Document for Layouts API

Description

Document for Layouts API

  • GridLayout
  • JustifedLayout
  • SquareLayout
  • FrameLayout
  • PackingLayout

Sub Modules.

  • Parallax

Steps to check or reproduce

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.