I’m attempting to use jQuery Masonry in a project and it’s not working properly: there’s a gap in the top-right corner of the grid. I’ve tried adjusting the grid width and margins, which results in either one block per row or all blocks being run together (but still with a gap topright.)
It doesn’t actually look like the blocks are being rearranged at all, though Masonry is applying its class and assigning absolute positioning to the elements as expected.
I was convinced that I was doing something wrong, but now I’m not so sure. I’ve taken a working fiddle from a similar question on Stack (http://stackoverflow.com/questions/11695574/jquery-masonry-almost-always-empty-spaces) and carefully modified it to use the dimensions I’m working with, and it just seems to be incapable of handling this selection of elements.
Fiddle: http://jsfiddle.net/dVPA9/4/
As apparently this is an indelible issue with Masonry and similar solutions, I decided I’d need to roll my own here. I also decided this would be better handled in PHP, as the default, floated DIVs will have large gaps in a lot of circumstances.
Here’s the algorithm I used, with comments to explain the fine points. This could have been done in jQuery trivially as well, but on the downside it’d look nasty for users without JavaScript.