Get new jQuery plugins just once a week



May 25, 2015

StackGrid-js | A jQuery plugin for stacking stuff similar to pinterest card layout

Stackgrid-js is a very simple and highly customizable jQuery plugin for stacking stuff.

Created by Adem



stackgrid-js jQuery plugin



A simple and fast JavaScript plugin to help you create fixed-width, variable-height grid layout.

Getting started

First, include stack-up.js to your project.

<!-- Example HTML -->
<div id="gridContainer">
  <div class="gridItem">...</div>
  <div class="gridItem">...</div>
  <div class="gridItem">...</div>

<!-- Scripts -->
<script src="js/stack-up.js"></script>

Minimum CSS requirements

#gridContainer {
  position: relative;

.gridItem {
  position: absolute;

.gridItem img {
  width: 100%;

Make sure all content inside the container are loaded before initializing stack-up. This is to make sure stack-up calculates the right height before plotting.

// One way to make sure everything is loaded is // to wrap the initializer inside window onload. window.onload = function() { // Create a stackup object. var stackup = new StackUp({ containerSelector: "#gridContainer", itemsSelector : "#gridContainer > .gridItem", columnWidth : 240, }); // Initialize stackup. stackup.initialize(); };


Customize stack-up to your needs.

  columnWidth        : 320,
  gutter             : 18,
  isFluid            : false,
  layout             : "ordinal", // ordinal, optimized
  numberOfColumns    : 3,
  resizeDebounceDelay: 350

// This function allows you to modify how each item is moved or animated.
stackup.config.moveItem: function(item, left, top, callback) { = left + "px";  = top + "px";
  // The callback function is required to continue operation.

// This one allows you to modify how the container scales.
stackup.config.scaleContainer: function(container, width, height, callback) {  = width + "px"; = height + "px";
  // The callback function is required to continue operation.

Reset and restack

Once the grid is initialized; you will need to call the restack method if you change any of the configurations.

stackup.config.layout = 'optimized'; stackup.restack();

The restack method will not work properly if you change something that affect the dimensions of the grid item. You will have to use reset instead. (This recalculates the grid stacking from top to bottom.)

stackup.config.columnWidth = 220;

You will also need to use the reset method if you add or remove any grid item.


The append method allows you to add a new grid item without re-calculating everything.

// Get container element.
var gridContainer = document.getElementById("gridContainer");

// Create a new grid item element.
var gridItem = document.createElement("div");
gridItem.setAttribute("class", "gridItem");
gridItem.innerHTML = "blah blah";

// Append the new grid item element into container element.

// Append it to stackup.

There is currently no prepend method.

That's it!


StackUp is licensed under the MIT license -

Copyright (C) 2017 Andrew Prasetya


Related posts:

Editable Listview
stackgrid-js jQuery plugin

jQuery plugin

Sign up for our weekly newsletter.

* We won't spam you ever
Couple Gift Ideas