Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Masonry reload & reloadItems not working

The masonry (v3) code:

$(function msnry(){
var columns = 3,
setColumns = function() { columns = $( window ).width() > 640 ? 3 : $(window).width() >    320 ? 2 : 1; };
setColumns();
$(window).resize(setColumns);

    // layout Masonry again after all images have loaded
    var $container = $('#portfoliocontent').masonry();
    var msnry;
    $container.imagesLoaded( function(){
    msnry = new Masonry( container, {
    itemSelector : '.item',
    columnWidth:  function( containerWidth ) { return containerWidth / columns;}
      });
});

My masonry container (aka my portfolio)

<div id="portfoliocontent" class="portfoliocontainer"></div>

My goal here is to hide all the divs with the class 'designshwr' which works, however the reload of masonry isn't working at all.

$('.engineeringiC').click(function(){
    if($('div.item').hasClass('designshwr')){
    $('div.item.designshwr').hide('fast');
    $('.portfoliocontainer').masonry('reloadItems');

}

Any suggestions? I've been scratching my head for the past week at different ways to get it to work, and I still haven't gotten any luck on it :(

like image 493
Andrew Squire Avatar asked Oct 04 '22 16:10

Andrew Squire


2 Answers

I finally resolved the issue in it's entirety.

$(function msnry(){
var columns = 3,
setColumns = function() { columns = $( window ).width() > 640 ? 3 : $(window).width() >          320 ? 2 : 1; };
setColumns();
$(window).resize(setColumns);

// layout Masonry again after all images have loaded
var $container = $('#portfoliocontent').masonry();
var msnry;
$container.imagesLoaded( function(){
msnry = new Masonry( container, {
itemSelector : '.item',
columnWidth:  function( containerWidth ) { return containerWidth / columns;}
  });
});

var $container = $('#portfoliocontent').masonry();

If anyone else encounters this problem it's probably because you applied the masonry initialization to your container variable. It's working great now :)

like image 105
Andrew Squire Avatar answered Oct 07 '22 19:10

Andrew Squire


I have faced same problem . May be my solution not efficient but whenever i have got optimum solution till now I have used this. You can try this hopefully it will helps to you as well.

$('.engineeringiC').click(function(){
    var $container = $('#portfoliocontent').masonry();
    if($('div.item').hasClass('designshwr')){
    $('div.item.designshwr').hide('fast');
    //$('.portfoliocontainer').masonry('reloadItems');
    setTimeout(function(){ $container.masonry() }, 400);
}
like image 34
Roopendra Avatar answered Oct 07 '22 18:10

Roopendra