我的网站包含大量内容。如果我只考虑网页中的文字,网页的大小约为1.2 MB。我知道如何延迟加载图像,但我想在用户向下滚动时加载内容。我在我的网站上使用HTML5和一些java脚本,但我只是java脚本的初学者。
答案 0 :(得分:3)
你可以自己编写代码,我只想在这里做一个例子:
[1]。窗口滚动到底部时触发:
$(window).scroll(function() {
// when the scroll reaches the bottom
if($('body').scrollTop()+$(window).height() >= $('body').height() - 20) {
// load more content
loadMore();
}
});
[2]。使用ajax来获取内容:
// remember where to continue, 0 at the beginning.
var part_loaded = 0;
function loadMore() {
$.get('get_more_info.html?part='+part_loaded++, function(data) {
// do the content append action here.
});
}