似乎這種技術(shù)是facebook最早實現(xiàn)的,好像叫bigpi,據(jù)說是facebook用來解決訪問量大的問題,好像說一個頁面的加載如果達(dá)到5秒,用戶就會離開,而這種技術(shù)可以將一部分內(nèi)容隱藏,用戶的滾動條往下拉它才出現(xiàn),顯然可以改變用戶的感覺。
參考代碼:
$(function () {
var i = 0;
$(window).bind(“scroll”, function (event) {
//滾動條到網(wǎng)頁頭部的 高度,兼容ie,ff,chrome
var top = document.documentElement.scrollTop + document.body.scrollTop; //??????
//網(wǎng)頁的高度
var textheight = $(document).height();
// 網(wǎng)頁高度-top-當(dāng)前窗口高度
if (textheight – top – $(window).height() <= 100) {
if (i >= 25) {
return; //控制最大只能加載到100條
}
$(‘#divContent’).css(“height”, $(document).height() + 400);
i++;
//可以根據(jù)實際情況,獲取ajax動態(tài)數(shù)據(jù)加載到 divContent中
var dataParas = ‘{ pageIdx:”‘ + i.toString() + ‘”}’; // 這里要直接使用JOSN作為webService參數(shù)
$.ajax({
type: “POST”,
dataType: “json”,
contentType: “application/json”,
data: dataParas,
url: “../MicroBlog.asmx/GetMicroBlogs”,
success: function (data) {
//將獲取到的JSON對象數(shù)組轉(zhuǎn)換為js對象
var blogs = eval(“MicroBlogs = ” + data.d);
//遍歷微博對象數(shù)組,追加到divContent中
for (var j = 0; j < 4; j++) {
$(‘’ + blogs.MicroBlogs.Sender + ‘’).appendTo($(‘#divContent’));
}
},
error: function () {
alert(“error occured!”);
}
});
}
});
});
//頁面加載時引發(fā)
$(document).ready(doc_ready);
//頁面加載時加載前4條微博
function doc_ready() {
var jsonParas = ‘{ pageIdx:”0″}’;
$.ajax({
type: “POST”,
dataType: “json”,
contentType: “application/json”,
data: jsonParas,
url: “../MicroBlog.asmx/GetMicroBlogs”,
success: function (data) {
var blogs = eval(“MicroBlogs = ” + data.d);
for (var j = 0; j < 4; j++) {
$(‘’ + blogs.MicroBlogs.Sender + ‘’).appendTo($(‘#divContent’));
}
},
error: ajax_error()
});
}
function ajax_error() {
//alert(“The call to webService is failed!!!!!”);
}
好像找個div專門存當(dāng)前的頁碼吧