All Projects → e-oj → Magic Grid

e-oj / Magic Grid

Licence: mit
A simple, lightweight Javascript library for dynamic grid layouts.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to Magic Grid

Popo
PoPo is the grid layout tool, the best choice for runtime layout.
Stars: ✭ 130 (-95.4%)
Mutual labels:  layout, grid, grid-layout
React Photo Layout Editor
Photo layout editor for react
Stars: ✭ 96 (-96.6%)
Mutual labels:  layout, grid, grid-layout
grid-layout
grid-layout is a layout engine which implements grid, can use in canvas/node-canvas
Stars: ✭ 43 (-98.48%)
Mutual labels:  grid, layout, grid-layout
Interior
Design system for the modern web.
Stars: ✭ 77 (-97.28%)
Mutual labels:  layout, grid, grid-layout
The Grid
Grid layout custom element with drag and drop capabilities
Stars: ✭ 122 (-95.68%)
Mutual labels:  layout, grid
Bootstrap Grid Css
The grid and responsive utilities classes extracted from the Bootstrap 4 framework, compiled into CSS.
Stars: ✭ 119 (-95.79%)
Mutual labels:  grid, grid-layout
Greedo Layout For Android
Full aspect ratio grid LayoutManager for Android's RecyclerView
Stars: ✭ 1,588 (-43.83%)
Mutual labels:  layout, grid
Muuri React
The layout engine for React
Stars: ✭ 163 (-94.23%)
Mutual labels:  layout, grid
React Awesome Styled Grid
A responsive 8-point grid system layout for React using styled-components
Stars: ✭ 157 (-94.45%)
Mutual labels:  grid, grid-layout
Leerraum.js
A PDF typesetting library with exact positioning and hyphenated line breaking
Stars: ✭ 233 (-91.76%)
Mutual labels:  layout, grid
Grid
This package has moved and renamed
Stars: ✭ 2,079 (-26.46%)
Mutual labels:  layout, grid
Stack Up.js
Create fixed width, variable height grid layouts.
Stars: ✭ 117 (-95.86%)
Mutual labels:  layout, grid
Flutter layout grid
A grid-based layout system for Flutter, inspired by CSS Grid Layout
Stars: ✭ 109 (-96.14%)
Mutual labels:  layout, grid-layout
Muuri
Infinite responsive, sortable, filterable and draggable layouts
Stars: ✭ 9,797 (+246.55%)
Mutual labels:  layout, grid
Shuffle
Categorize, sort, and filter a responsive grid of items
Stars: ✭ 2,170 (-23.24%)
Mutual labels:  layout, grid
Reactsimpleflexgrid
A way to quickly add a Grid Layout to your React app 🚀
Stars: ✭ 181 (-93.6%)
Mutual labels:  grid, grid-layout
Angular Grid Layout
Responsive grid with draggable and resizable items for Angular applications.
Stars: ✭ 163 (-94.23%)
Mutual labels:  grid, grid-layout
Grd
A CSS grid framework using Flexbox. Only 321 bytes (Gzipped).
Stars: ✭ 2,210 (-21.83%)
Mutual labels:  grid, grid-layout
React Rasta
React Rasta is a powerful and flexible grid system for React
Stars: ✭ 88 (-96.89%)
Mutual labels:  grid, grid-layout
React Native Flexbox Grid
Responsive Grid for React Native
Stars: ✭ 95 (-96.64%)
Mutual labels:  layout, grid

MIT License Downloads

Buy Me A Coffee

Magic Grid Tweet

A simple, lightweight Javascript library for dynamic grid layouts.

Creating a dynamic grid layout has never been easier. With Magic Grid, all you have to do is specify a container and listen for changes. A few other configuration options are available for convenience but it's all very simple. Check it out live on JSFIDDLE. You can read about the implementation details on CodeBurst.

Note: Every item in the grid must have the same width.

Sample Usage

demo

Why not CSS Grid?

This question is addressed in the article:

Implementing a grid layout can quickly turn into a tricky task. If you have grid items that are always the same height, then you can probably make do with a Flexbox grid or some other CSS grid implementation. However, if you’re dealing with user-generated content, chances are, you don’t have the luxury of equal height components. One longer or shorter component would either stretch the other components in its row, or leave some unpleasant whitespace at the bottom of the row. All of a sudden, our beloved CSS grid has become insufficient.

Check out CSS Grid AMA's issue #19 for a response from CSS expert @rachelandrew:

That's not something grid is designed for. Grid is two dimensional so you are always working in both rows and columns at the same time. You can't use grid to do a "masonry" style layout like that. You could place items in that way if you had a lot of rows and managed how many each spanned, but you can't use auto-placement to get that kind of layout.

Ports

Repo Author
Vue-Magic-Grid @imlinus
Magic-Grid-React @IniZio

Getting Started

Step 1

Get Magic Grid via NPM:

npm install magic-grid

Or CDN

<script src="https://unpkg.com/magic-grid/dist/magic-grid.cjs.js"></script>

<!-- or (minified) -->
<script src="https://unpkg.com/magic-grid/dist/magic-grid.min.js"></script>

Step 2 (skip if using CDN)

Import Magic Grid:

import MagicGrid from "magic-grid"

// or
let MagicGrid = require("magic-grid");

You can also pull Magic Grid directly into your html

<script src="node_modules/magic-grid/dist/magic-grid.cjs.js"></script>

<!-- or (minified) -->
<script src="node_modules/magic-grid/dist/magic-grid.min.js"></script>

Step 3

You're good to go! If you used a script tag, the library can be referenced via the global variable, MagicGrid.

let magicGrid = new MagicGrid(...);

magicGrid.listen();

Usage

Static content:

If your container doesn't have any dynamically loaded content i.e., all its child elements are always in the DOM, you should initialize the grid this way:

let magicGrid = new MagicGrid({
  container: "#container", // Required. Can be a class, id, or an HTMLElement.
  static: true, // Required for static content.
  animate: true, // Optional.
});

magicGrid.listen();

Dynamic content:

If the container relies on data from an api, or experiences a delay, for whatever reason, before it can render its content in the DOM, you need to let the grid know the number of items to expect:

let magicGrid = new MagicGrid({
  container: "#container", // Required. Can be a class, id, or an HTMLElement.
  items: 20, // For a grid with 20 items. Required for dynamic content.
  animate: true, // Optional.
});

magicGrid.listen();

API

MagicGrid(config)

config (required): Configuration object

The MagicGrid constructor. Initializes the grid with a configuration object.

let magicGrid = new MagicGrid({
  container: "#container", // Required. Can be a class, id, or an HTMLElement
  static: false, // Required for static content. Default: false.
  items: 30, // Required for dynamic content. Initial number of items in the container.
  gutter: 30, // Optional. Space between items. Default: 25(px).
  maxColumns: 5, // Optional. Maximum number of columns. Default: Infinite.
  useMin: true, // Optional. Prioritize shorter columns when positioning items? Default: false.
  useTransform: true, // Optional. Position items using CSS transform? Default: True.
  animate: true, // Optional. Animate item positioning? Default: false.
  center: true, //Optional. Center the grid items? Default: true. 
});

.listen()

Positions the items and listens for changes to the window size. All items are repositioned whenever the window is resized.

let magicGrid = new MagicGrid({
  container: "#container", // Required. Can be a class, id, or an HTMLElement
  static: true, // Required for static content.
  animate: true, // Optional.
});

magicGrid.listen();

.positionItems()

This function is useful in cases where you have to manually trigger a repositioning; for instance, if a new element is added to the container.

let magicGrid = new MagicGrid({
  container: "#container", // Required. Can be a class, id, or an HTMLElement
  items: 30, // Required for dynamic content.
  animate: true, // Optional
});

magicGrid.listen();

// get data from api
// append new element to DOM

// reposition items
magicGrid.positionItems();

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].