Masonry.js (adaptive mesh in the junction of vertical) – manual, connection and basic setting

Like that tired, to be honest, dull and commonly used Bootstrap grid, and I wanted to implement the grid blocks in the junction of the vertical c full filling. All hands did not reach, but rallied and finally decided to switch to Masonry.js in their projects. Masonry.js – jQuery is a plug – in that allows you to implement a grid of blocks by Pinterest type, i.e.-grid blocks become butt vertically and fill the entire page without a rigidly fixed block height. In addition, the Masonry grid.js is adaptive.

The main advantages of using Masonry.js that I found for myself:

  • ease of script;
  • easy setup;
  • stylish unadulterated look;
  • adaptability;
  • with a small number of settings, the possibilities are quite wide;

So, let’s start the connection and basic setup.

For starters the reference on the official site, where can be download himself plugin and view examples: /

Connecting Masonry.JS to site

The connection of the library to be reduced to the standard connection, as any js to the site. Download the plug-in link, throw on FTP in the folder on the site and add to the head:

path_to – path to the script on the hosting

For WordPress you can connect a “kosher way”:

Initialization and configuration of Masonry.js

For example, we will use this here is a standard layout template:

Ie the container which will contain the blocks will have the class grid and the blocks (mesh) grid item. The markup is presented for example – later in the Masonry initialization script.js you can register any of your own classes used on your site.

And the script itself initialized with the basic settings (placed before the closing /body tag):


jQuery + migrate (WordPress):


Here we declare the above classes and specify the width of the blocks (columnWidth) in pixels.

After that, the grid should already be running.

Importantly! If you are connecting a script to work with existing classes, the grid can be broken by already defined CSS styles, so if you use your classes with already defined styles, if you encounter errors and do not work correctly in the first place, see CSS styles used classes.

Examples of work can be viewed on the official website, at home page of our website, on the test blog, on which experiment, Ah and of course same all known Pinterest. From myself I will note – plugin Masonry.js is very cool, with easy setup and wide possibilities, so I will use it more often in my works. Well, in the following articles will consider a more fine-tuning Masonry.js and nuances that emerged during the”operation”.

masonry.js to set the connection


Leave a Reply

Your email address will not be published. Required fields are marked *