Masonry JS Overlapping Items Masonry JS Overlapping Items jquery jquery

Masonry JS Overlapping Items


The problem is your images. By the time masonry is called, your images haven't loaded. So it's assuming the height of your elements WITHOUT the height of the image being factored in.

If you refresh your screen after the images are already cached, you'll see that it loads correctly. If you then clear cache and refresh, you'll see they overlap again.

Four Five options:

  • Wait until the images are finished loading (there are plugins that you can wait until all images inside a certain div are loaded, for example)
  • Wait for the load event instead of the ready event. Instead of using jQuery(function($){ use jQuery(window).on('load', function(){ var $ = jQuery; and you'll see the results.
  • Re-apply masonry after the images load (Don't like this one... you'd see flicker)
  • My favorite, don't use masonry here! Disable JS on your page and look at the layout. It's what you want. All the divs are even heights and even widths. There's not really a reason to use masonry here. Just float your elements and let them display in the grid naturally.
  • EDIT: another option. Specify a height of the divs so the height doesn't depend on the images it's loading.


You need to initiate Masonry after all images are loaded.If you are using jQuery try:

var $container = $('#container');// initialize Masonry after all images have loaded  $container.imagesLoaded( function() {  $container.masonry();});

for other options see Masonry docs - http://masonry.desandro.com/layout.html#imagesloaded


I've solved this issue with a settimeout function. By allowing a second or so to pass (depending on the # and file size of the images being downloaded) you can download the images first then apply masonry.

                $(document).ready(function(){                                                                                                                                   setTimeout(function() { masonry_go();masonry_go2();}, 1000);                                                                                });                 $(window).resize(function()             {                // jQuery                $('.grid').masonry( 'destroy')                $('.grid2').masonry( 'destroy')                                 setTimeout(function() { masonry_go();masonry_go2();}, 1000);                                                                                });                             function masonry_go(){                $('.grid').masonry({                  // options                  itemSelector: '.grid-item',                  columnWidth: 300                });                                     }                   function masonry_go2(){                $('.grid2').masonry({                  // options                  itemSelector: '.grid-item2',                  gutter: 15,                  columnWidth: 200                });                                     }