Skip to content

Instantly share code, notes, and snippets.

@jz5
Created June 4, 2014 16:58
Show Gist options
  • Save jz5/c5fe88bf32f989fad802 to your computer and use it in GitHub Desktop.
Save jz5/c5fe88bf32f989fad802 to your computer and use it in GitHub Desktop.
(function($) {
var mainContent = $("#primary"),
height = mainContent.outerHeight(), // コンテンツの縦幅 この幅までモジュールを追加する
aside = $("#content-sidebar"), // モジュールを追加する領域
buffer = 80;
function getMoreContent() {
$.ajax({
type: "GET",
url: "http://***.azurewebsites.net/api/values", // 追加モジュールのデータを返す API を用意
success: function (data) {
if (data && data.length > 0) {
for (var i = 0; i < data.length; i++) {
var d = data[i];
var html = '<div><a href="' + d.DetailPageUrl + '"><img src="' + d.ImageUrl + '" title="' + d.Title + '" /><br />' + d.Title + '</a></div>';
$("<aside />", {
"class": "sidebar-box",
"id": "sidebar-box-" + i,
"html": html,
"css": {
"position": "relative",
"left": 25
}
// Fancy revealing of new content
}).hide().appendTo(aside).fadeIn(200, function () {
$(this).animate({
"left": 0
});
});
// If after getting new module, sidebar is still too short, start over
if ((height > (aside.outerHeight() + buffer))) {
console.log("aside.outheight: " + aside.outerHeight());
} else {
break;
}
}
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log(textStatus);
}
});
}
// Initial test
if (height > (aside.outerHeight() + buffer)) {
console.log("height: " + height);
getMoreContent();
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment