I only have a first look at jQuery Masonry, and what does it look like, maybe the plugin did not start at all? This usually happens to me when I have a syntax error in my code. Your JS looks a bit sketchy, and, hmm ... gotcha! Use this:
$(function() { $('#container').masonry({ itemSelector: '.box', columnWidth: function( containerWidth ) { return containerWidth / 5; } }); });
It worked.
That's why the right indentation is important - if you had it, the problem (and the solution) would be almost immediately obvious to you. First you called:
$(window).load() { }
These are two completely separate statements, almost the same as:
$(window).load();
You need to pass an anonymous function as the parameter .load()
, for example:
$(window).load ( function() { } )
In addition, you had a semicolon in the settings object after defining the columnWidth
function - just as if you typed
{ name1: 'value1', name2: 'value2'; // <-- SYNTAX ERROR name3: 'value3', // it okay to leave a trailing comma, though }
It always attracts me too, but itβs much easier to see with the right margin.
Conclusion: teach yourself good indentation. Also, use the JS console to check for syntax errors; this in itself helps to tremendously understand what is wrong.
source share