View on GitHub

Clay

Clay is an easy to use lightweight masonry-like layout engine.

Download this project as a .zip file Download this project as a tar.gz file

Features

See the Pen KqrIJ by Shawn (@shaw3257) on CodePen.

Installation


              <script type="text/javascript" src="clay.js"></script>
          

Usage

Initalize Clay


              /*
              * Creates a default Clay layout
              * Takes in the container's selector as the first argument
              */
              var clay = new Clay('.container');

              /*
              * Creates a customized Clay layout
              */
              var clay = new Clay('.container', {
                minWidth: 100, 
                gutter: 20, 
                padding: 15, 
                itemSelector: '.myitem'
              });

            

Prepend Items


              var item = document.createElement('div');
              
              /*
              * Adds new item to dom and into Clay
              */
              clay.prepend(item);
              
              /*
              * Re-measure and re-layout the grid
              */
              clay.reLayout();

            

Append Items


              var item = document.createElement('div');

              /*
              * Adds new item to dom and into Clay
              * Also performs a layout of item since appending
              * can be easily optimized to not require a complete
              * relayout of grid
              */
              clay.append(item);