【发布时间】:2015-02-24 20:43:30
【问题描述】:
滚动时无法加载照片
SyntaxError: missing ) 后参数列表 1:221 ReferenceError: json_loads 未定义 1:236
这是加载照片并显示在网页上的功能
function json_loads(load_count, photo_count) {
$.getJSON('/json_album_detail/', {
'album_id': {{ object.id }},
'count': photo_count, // min 3!!
'load_count': load_count
}, function(data) {
console.log(data);
for(item in data) {
last_item = item;
id = 'scrolling';
console.log('Id: ' + id)
}
console.log(data.length);
for(i=1, count=2; i<=last_item; i++, count++) {
newdiv = document.createElement("div");
mydiv = document.getElementById(id);
newdiv.className='project-img';
newhref = document.createElement("a");
newimg = document.createElement("img");
newimg.setAttribute('src', data[i].url);
newhref.setAttribute('href', data[i].url);
newdiv.appendChild(newhref);
newdiv.appendChild(newimg);
mydiv.appendChild(newdiv);
}
}
}
如果滚动到底部则运行函数
var scroll_count = 0
var load_count = 3
var photo_count = 4
$(window).on("scroll", function() {
var scrollHeight = $(document).height();
console.log('scrollHeight: ' + scrollHeight);
var scrollPosition = $(window).height() + $(window).scrollTop();
console.log('scrollPosition: ' + scrollPosition);
console.log('To event = ' + (scrollHeight - scrollPosition) / scrollHeight);
if ((scrollHeight - scrollPosition) / scrollHeight < 0.01) {
json_loads(load_count, photo_count);
scroll_count = scroll_count+1;
console.log(scroll_count);
photo_count = photo_count+1;
load_count = load_count+1;
}
});
测试地点:http://54.93.51.225/album/1/
【问题讨论】:
标签: javascript jquery json function autoload