desandro / masonry

:love_hotel: Cascading grid layout plugin
https://masonry.desandro.com
16.38k stars 2.11k forks source link

Re-initiliaze the masonry #1079

Closed Webinsane closed 5 years ago

Webinsane commented 5 years ago

Hello. I am using latest version of masonry. I have issues on my search results page as I am opening and closing sidebar which pushes the images to smaller size. It works nicely only problem is that masonry leaves spaces between images. If I launch Firefox inspect tool it looks OK probably because inspect tool re-initializes the masonry. I tried to achieve this following some solutions on the web, but with no luck. The perfect solution would be to arrange masonry when opening and closing sidebar. This my code for masonry:

$(window).load(function(){
    // Rooms Masonry
    var container = $('.rooms.rooms-masonry > .rooms-inside');
    container.masonry({
      itemSelector: '.room',
      columnWidth: 1,
    });
    showSearchFields(window.SEARCH_TYPE);

});
desandro commented 5 years ago

After the container size has changed, you should trigger .masonry() to re-layout the items.