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

rugbert picture rugbert · Sep 19, 2011 · Viewed 26.3k times · Source

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.

Answer

Kostyantyn picture Kostyantyn · Feb 10, 2012

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>