Greedy shortest-column, not round-robin
Dealing tiles across columns in order is simpler to write and looks wrong the moment two tall images land in the same column. Putting the next tile wherever the total is currently smallest is the whole idea.
Pinterest-style column grid for MooTools
A MooTools plugin that packs tiles of different heights into even columns, the way Pinterest does.
Problem
Solution
Outcome
~120
lines of source
1
public method
2
events
4
options
System design · Pipeline · Decisions
System Architecture
How It Works
Initialise
new MooPin({ container }) measures the container, counts columns from the first tile width, and keeps a running height per column.
Layout pass
Each tile is placed in whichever column is currently shortest, then absolutely positioned. That greedy choice is what keeps the bottom edge roughly even.
Re-entry
onWindowResize re-runs the whole pass. Infinite scroll appends markup and calls render() again — no incremental state to keep in sync.
Key Decisions
Dealing tiles across columns in order is simpler to write and looks wrong the moment two tall images land in the same column. Putting the next tile wherever the total is currently smallest is the whole idea.
The layout pass is idempotent. That is why the infinite-scroll demo is six lines of host code: append the new markup, call render() again. It costs a full re-layout on every trigger, which was fine at demo sizes.
The sites that needed this were already on MooTools. A native plugin beat asking those teams to pull in jQuery for one layout effect.
Evaluation
There is no test suite; correctness was two browsers and my eyes. Reading it now, the resize handler fires on every resize event with no throttle, three loop variables leak to the global scope, column width is read off the first tile and assumed for the rest, and tiles have to carry explicit image dimensions — measure before decode and every height comes back zero.
What I'd Change
Get in Touch