我正在使用下面的代码创建一个合理的图库:http://jsfiddle.net/thirtydot/EDp8R/3/
我还使用infinitesscroll来加载更多的项目。
当前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
}
这段代码适用于加载的第一个项目块,但忽略了无限滚动加载的项目
已经试过了(在另一个类似的帖子中找到了答案):
$("head").append($('<style>div#posts:after { content: "";width:100%;display:inline-block;font-size:0;line-height:0; }</style>'));
我找到了答案每个新元素都应该添加一个空格只是添加了$(this).before(" ");
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(" ");
$(this).css("width", $(this).width());
});
$('#posts').removeClass('posts').addClass('posts');
}
);