Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Masonry not working.

I had it working but for some reason it has just stopped working and I don't know what I have done.The box divs are floated left, I just don't know where I've gone wrong.

Jquery

var $container = $('.work');            
$container.imagesLoaded(function(){                 
   $container.masonry({
      itemSelector: '.box',
      isAnimated: true,
      columnWidth: 250                  
   });
});

HTML

<div id="part-one" class="work">
   <div class="box col2"><img src="_assets/images/one.jpg" alt="" /></a></div>
   <div class="box col2"><img src="_assets/images/two.jpg" alt="" /></a></div>
   <div class="box col2"><img src="_assets/images/three.jpg" alt="" /></a></div>
   <div class="box col2"><img src="_assets/images/four.jpg" alt="" /></a></div>
   <div class="box col2"><img src="_assets/images/five.jpg" alt="" /></a></div>
</div>

CSS

.work {
   margin-left:98px;
   top:0;
   max-width:1600px;
   padding-bottom:100px;
   position:absolute;
}
like image 728
green_arrow Avatar asked Aug 23 '12 09:08

green_arrow


1 Answers

Remove your columnWidth property and Masonry will use the width of the first item element. (Docs).

Check out this JSFiddle. http://jsfiddle.net/s8PhS/14/

If you resize the HTML container in JSFiddle it will also resize dynamically.
I also added some extra <div> elements for demo purposes and a Odd Five element with a different height, and you can see the masonry plugin kicks in and position's the elements perfectly.

So basically, remove the property columnWidth: 250 and let Masonry pick it up dynamically.

In JSFiddle, this seems to solve your problem.


Just a tip: I used this same jquery.masonry plugin recently, but also wanted to sort my elements, I found this amazing plugin called Isotope which is amazing and much more customizable.

Check out the Demo on the Homepage!

like image 57
Anil Avatar answered Oct 18 '22 10:10

Anil