Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am creating a justified gallery using the code here: http://jsfiddle.net/thirtydot/EDp8R/3/

I also use infinitescroll to load more items.

Current js:

$("#posts").infinitescroll({
navSelector  : '#page_nav',    // selector for the paged navigation 
nextSelector : '#page_nav a',  // selector for the NEXT link (to page 2)
itemSelector : '.item',     // selector for all items you'll retrieve
loading: {
    finishedMsg: 'No more pages to load.',
    img: 'http://i.imgur.com/qkKy8.gif'
  }
},

function( newElements ) {
            $( newElements ).each(function() {
                $(this).css("width", $(this).width());
            }); 
            $('#posts').removeClass('posts').addClass('posts');
}
);      

CSS:

#posts.posts{
    text-align: justify;
    -ms-text-justify: distribute-all-lines;
    text-justify: distribute-all-lines;
}

#posts.posts .post{
    height: 250px;
    vertical-align: top;
    display: inline-block;
    *display: inline;
    zoom: 1
}

#posts.posts:after {
    content: '';
    width: 100%;
    display: inline-block;
    font-size: 0;
    line-height: 0
}

This code works for the fist chunk of loaded items, but ignores the items loaded with infinite scroll

Already tried this (found as an answer in another similar post):

$("head").append($('<style>div#posts:after { content: "";width:100%;display:inline-block;font-size:0;line-height:0; }</style>'));
share|improve this question

1 Answer

up vote 0 down vote accepted

I found the answer Each new element should have a space added Just added it with $(this).before("&nbsp;");

New is is:

$("#posts").infinitescroll({
navSelector  : '#page_nav',    // selector for the paged navigation 
nextSelector : '#page_nav a',  // selector for the NEXT link (to page 2)
itemSelector : '.item',     // selector for all items you'll retrieve
loading: {
    finishedMsg: 'No more pages to load.',
    img: 'http://i.imgur.com/qkKy8.gif'
  }
},

function( newElements ) {
            $( newElements ).each(function() {
                $(this).before("&nbsp;");
                $(this).css("width", $(this).width());
            }); 
            $('#posts').removeClass('posts').addClass('posts');
}
); 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.