Masonry is a very powerful jQuery dynamic grid layout plug-in that can help developers quickly develop interface effects similar to clip art. The difference from the effect of float in CSS is that float is arranged horizontally first, and then vertically. Using Masonry, elements are arranged vertically, and then the next element is placed in the next development area in the grid. This effect minimizes vertical gaps between elements of different heights. As follows:
As you can see in the picture above, using float to process elements of different heights in grid layout will make the spacing between elements in the vertical direction larger, but after using Masonry, the spacing becomes smaller.
Usage
First pour the class library, as follows:
Then, perform masonry on the element container, as follows:
html code
css
If there are images in the element you load, you need to ensure that Masonry is executed after all images have been loaded. You need to call the following code: