OK, so you are doing 12 posts here:
function getPosts() {
$.getJSON('(TUMBLR_API_KEY)',
function(r) {
var posts = r.response.posts;
for (var i = 0; i < 12; i++) {
var html = "";
if (posts[i].type === "text") {
html = formatTextHTML(posts[i]);
} else if (posts[i].type === "photo") {
html = formatPhotoHTML(posts[i]);
}
appendPostToPage(html);
}
});
}
You can use the modulas operator to work every time you loop three messages, for example:
var html = '<div class="container">';
for (var i = 0; i < 12; i++) {
if( (i%3 == 0 ){
html += '<div class="row">';
}
html += '<div class="span4">';
html += '<div class="individualpost" style="background-image:url(' + photo.original_size.url + '); background-position:center center;-webkit-background-size: cover;-moz-background-size: cover;-o-background-size: cover;background-size: cover; height:360px; width:100%;"></div>';
html += '</div>';
if( i%3 == 2 ){
html += '</div>';
}
}
html += '</div>';
Mina is a little rude, but this should work ...
source
share