Responsive Grid Layout Builder In Vanilla JavaScript – EasyGrid

Category: Javascript , Layout , Recommended | December 16, 2020
Author: BMSVieira
Views Total: 252 views
Official Page: Go to website
Last Update: December 16, 2020
License: MIT

Preview:

Responsive Grid Layout Builder In Vanilla JavaScript – EasyGrid

Description:

An easy, framework-agnostic JavaScript grid library helps developers quickly build a responsive, customizable, and animated grid layout on their sites or web apps.

Well-suited for any type of grid layouts like Mosaic, Masonry, Equal Height, Image Tiles, and much more.

See Also:

How to use it:

1. Add the stylesheet easygrid.css and JavaScript easygrid.js to the webpage.

<link rel="stylesheet" href="css/easygrid.css" />
<script src="js/easygrid.js"></script>

2. Create a container to hold the grid.

<div id="grid"></div>

3. Initialize the library to render a basic grid.

const demo = new EasyGrid({
      selector: "#grid",
      // options here
});

4. Add grid items using the AddItem method.

// add a single grid item
demo.AddItem({
  items: "Any HTML Here"
});

// add an array of grid items
const myElements = [item1, item2, item3, ...]
demo.AddItem({
  items: myElements
});

// trigger a function after items have been added
demo.AddItem({
  items: myElements,
  onComplete: function(){
    console.log("Completed!");
  }
});

5. Full options to customize the grid layout.

const demo = new EasyGrid({

      // grid selector
      selector: "#defaultId",

      dimensions: {
        width: "150",
        height: "100",
        margin: "5",
        minHeight: "100",
        maxHeight: "300"
      },

      // config animations here
      animations: {
        fadeInSpeed: "100",
        addItemSpeed: "100"
      },

      // fetch items from HTML
      config: {
        fetchFromHTML: true,
        filter: true
      },

      // additional styles
      style: {
        background: "rgb(96, 120, 134)",
        borderRadius: "5"
      },

      responsive: [
        {
          breakpoint: 500,
          columns: 2
        },
        {
          breakpoint: 300,
          columns: 1
        }
      ]
      
});

6. More API methods.

// clear grid items
demo.Clear();

// setup the grid
demo.SetupEasyGrid();

// re-position the grid
demo.Refresh();

// filter all elements that match specific class
demo1.Filter();

Changelog:

v1.3 (12/16/2020)

  • Stable Version with Filtering

v1.2 (12/12/2020)

  • Added Filtering
  • Code Update

v1.1 (12/08/2020)

  • New Responsive Settings & Overall Performance

v1.0 (12/08/2020)

  • Stable Version of EasyGrid

You Might Be Interested In:


Leave a Reply