This is the same question as this one, but I have a repro of the issue on JSFiddle up here. So I thought I'd repost.
JQuery Masonry seems to only assess the children of its container once, on first run. After that, it's impossible to get it to look at the DOM again to get it to reassess its children.
You have to pass the new content to Masonry's appended method:
$("#container").append(content).masonry("appended", content);
I updated your fiddle here.
I seem to have solved this by adding a line to reload the "bricks" to the _reLayout
function in the JQuery Masonry code at line 305.
_reLayout : function( callback ) {
// This is my added line.
// Items might have been added to the DOM since we laid out last.
this.reloadItems();
// reset columns
var i = this.cols;
this.colYs = [];
while (i--) {
this.colYs.push( this.offset.y );
}
// apply layout logic to all bricks
this.layout( this.$bricks, callback );
},
// ====================== Convenience methods ======================
// goes through all children again and gets bricks in proper order
reloadItems : function() {
this.$bricks = this._getBricks( this.element.children() );
},
reload : function( callback ) {
this.reloadItems();
this._init( callback );
},
Anyone see any problem with this?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With