5

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 :(

4

2 回答 2

3

我终于彻底解决了这个问题。

$(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();

如果其他人遇到此问题,可能是因为您将砌体初始化应用于容器变量。它现在工作得很好:)

于 2013-07-02T23:27:02.890 回答
1

我遇到了同样的问题。可能是我的解决方案效率不高,但是到目前为止,每当我获得最佳解决方案时,我都使用了它。你可以试试这个,希望它对你也有帮助。

$('.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);
}
于 2013-07-01T09:56:43.650 回答