What is this?
This is a masonry script in ~100 lines of vanilla JS. It has two fill modes. The setting fillHorizontal = true adds each item to the next column (from left to right). When you set it to false, it adds each new item to the column with the lowest height. The script ‘relayouts’ after each image load and debounces on resize.
How to use it?
Layout your items using CSS grid and add the class masonry.
<div class="grid masonry">
<div>
<img src="image_url.jpg" />
<h3>Lorem ipsum 1</h3>
<p>Lorem ipsum dolor sit amet.</p>
</div>
...
</div>
<link rel="stylesheet" href="masonry.css" />
<script src="masonry.js"></script>
Set the fill mode in the first line of the masonry.js file:
var fillHorizontal = false;
License
This code is licensed WTFPL.