Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery masonry breaks(stacks images) in chrome/safari but only on first load

It seems that when I try to load the page, all the images are stacked on top of one another. But if you were to click a link which takes you to the same page (like the home link) then masonry kicks in. So I think masonry is loading too early, like before jquery readies the page or something.

Here my jquery call:

$(document).ready(function(){
    $('#image_roll_container').masonry({
        itemSelector: '.box'
    });

....

Here's the page in question:

http://ratattoos.com/

it works just fine in firefox and IE8.

like image 614
rugbert Avatar asked Sep 19 '11 20:09

rugbert


2 Answers

I've managed to fix this problem with the following tweak:

<script type="text/javascript">
    $(document).ready(function(){
        $('img').load(function(){
            $(".content_photo").masonry();
        });
        $(".content_photo").masonry();
    });
</script>
like image 94
Kostyantyn Avatar answered Sep 21 '22 08:09

Kostyantyn


looks like I needed a plugin called imagesLoaded in order for the Monsry script to work properly with the likes of chrome and safari

like image 11
rugbert Avatar answered Sep 21 '22 08:09

rugbert