9

So I'm using the isotope masonrylayout

$('section').isotope({itemSelector:'article',layoutMode:'masonry',transformsEnabled: false, animationEngine: 'jquery',masonry:{columnWidth:8}});

The problem is that if I don't set the height for the article in css, the layout doesn't look good the items overlap and stuff, but I can't set a fixed height for the elements, since they are blog posts and can change in size, do you guys have any tips on how to solve this?

RRikesh
  • 12,503
  • 5
  • 45
  • 65
Uffo
  • 8,424
  • 20
  • 78
  • 148

3 Answers3

26

Problem solved, you need to call $(window).load instead of $(document).ready(

Uffo
  • 8,424
  • 20
  • 78
  • 148
  • Works for me too, using defaul layout tho. Interestingly enough the default isotope example uses `$(document ).ready()`.. [Codepen link](http://codepen.io/desandro/pen/nFrte) – Cammy Jan 27 '16 at 10:16
  • While window load may work, I do not recommend it. window load waits for ALL assets on the page to load (CSS, JS, img, iframe, etc). imagesLoaded is better suited as you can target only the images within the Isotope instance to load. – desandro Mar 25 '16 at 18:31
8
var $container = $('#container').imagesLoaded( function() {
  $container.isotope({
    // options
  });
});

See Isotope - imagesLoaded

desandro
  • 2,836
  • 1
  • 20
  • 29
0

This happend because isotope doen't know your image sizes before load. The better way to do it is using a loading indicator (maybe with imageLoaded plugin) to load the images and then perform an Insert or append with isotope. You will have a smooth navigation and the ilusion of a faster loading site than using $(window).load().