views:

108

answers:

1

Hi,

I'm using masonry for layout.

I have set up a filter for the divs using the following code:

$("#logo").click(function() {
    $(".box").fadeIn();
    $(".box:not(.logo)").fadeOut();
});

when I select an item, I want masonry to reload the layout so that the items are reshuffled and that there aren't blank spaces.

Ideas?

thanks

A: 

It appears that Masonry won't reorganize the layout unless the .box is removed from the layout. So you can either remove the box completely or append it into a hidden div.

I wasn't sure how you wanted the script to function, so I made a demo with a logo and reset button. If you run the script more than once you'll notice that all the hidden divs were appended to the end of the layout so you won't see much changing at the top.

Check out the demo here (Note: the bin will not function properly at times, just hit the [ Run ] button again and it should work)

New HTML

<div id="holder"></div>

Script

$(document).ready(function(){

 $('#main').masonry({
    columnWidth: 100, 
    itemSelector: '.box',
    animate: true
 });

 $('#logo').click(function(){
  $(".box").fadeIn( '300' );
  $('.box:not(.logo)').fadeOut( '300', function(){ 
   $(this).appendTo('#holder') ;
  });
  setTimeout(function(){ $('#main').masonry() }, 400); // calling masonry to reorganize the layout after the all of the animation has occurred.
 })

 $('#reset').click(function(){
  $('#holder').find('.box')
   .hide()
   .appendTo('#main')
   .fadeIn( '300' );
  setTimeout(function(){ $('#main').masonry() }, 400);
 })

})
fudgey
Great response. Unfortunately it's functionality is only halfway there...see: http://jsfiddle.net/Hf8vT/ I added a new class "web" and I would like it to reset when each item is selected. Currently, if I select logo and then web, it shows nothing because there aren't any items that share both classes. I'm trying a new filtering technique - but I'm still having the same issue. If you don't mind taking a look - jasondaydesign.com/js/jquery.filterablepack.js
Jason
however, if I could get your above to work I will use it. I'm trying several different filtering techniques. I'm also using easylistsplitter to get a masonry style layout with list filtering - unfortunately, the filters only work on the first column - see jasondaydesign.com/index2.html
Jason
What about this update (http://jsfiddle.net/Hf8vT/4/)?
fudgey
I just tried this - http://jsfiddle.net/phVxf/ and got it to work.I'll compare it to yours. I'm not quite understanding what you did, but I see that it works too - but occasionally (after multiple clicks) some divs will float in space instead of reshuffling correctly. I think I'm okay with my version, as it reloads all of them and then fades out the correct ones.
Jason
Now I have one more issue - if you look at my site jasondaydesign.com - you'll see under the photos is a toggle. Unfortunately, the toggle content gets hidden under the other divs. Is it even possible to have the toggle with masonry, or do I need to get rid of it?thanks for all of your help!
Jason
well now I see my version is also not shuffling correctly sometimes too. Is it the timeout speed?
Jason
also, how would I change the :button to use with menu links?
Jason
Updated again (http://jsfiddle.net/Hf8vT/10/) with menu links. I also increased the timeout speed to 500 and the blanks spaces don't happen anymore.
fudgey
I'm not sure what to do about the content you toggle, maybe it'd be better to add that to the lightbox or into a tooltip?
fudgey
I think you're right. Thanks so much for your help, you've been very helpful and taught me a few new things!
Jason